Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zoom commands #4367

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions background_scripts/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ const Commands = {
"closeOtherTabs",
"moveTabLeft",
"moveTabRight",
"zoomIn",
"zoomOut",
"zoomReset",
],
misc: ["showHelp", "toggleViewSource"],
},
Expand Down Expand Up @@ -381,6 +384,9 @@ const Commands = {
"enterVisualLineMode",
"toggleViewSource",
"passNextKey",
"zoomIn",
"zoomOut",
"zoomReset",
],
};

Expand Down Expand Up @@ -454,6 +460,9 @@ const defaultKeyMappings = {
"X": "restoreTab",
"<a-p>": "togglePinTab",
"<a-m>": "toggleMuteTab",
"zi": "zoomIn",
"zo": "zoomOut",
"z0": "zoomReset",

// Marks
"m": "Marks.activateCreateMode",
Expand Down Expand Up @@ -547,6 +556,10 @@ const commandDescriptions = {
moveTabLeft: ["Move tab to the left", { background: true }],
moveTabRight: ["Move tab to the right", { background: true }],

zoomIn: ["Increase zoom on current tab", { background: true }],
zoomOut: ["Decrease zoom on current tab", { background: true }],
zoomReset: ["Reset zoom on current tab", { background: true }],

"Vomnibar.activate": ["Open URL, bookmark or history entry", { topFrame: true }],
"Vomnibar.activateInNewTab": ["Open URL, bookmark or history entry in a new tab", {
topFrame: true,
Expand Down
19 changes: 19 additions & 0 deletions background_scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ const mkRepeatCommand = (command) => (function (request) {
}
});

const setZoom = (tabId, callback) => {
chrome.tabs.getZoom(tabId, (factor) => {
Copy link
Owner

@philc philc Dec 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use await for all of these chrome zoom APIs, rather than callbacks.

chrome.tabs.setZoomSettings(tabId, { scope: "per-tab" }, () => {
chrome.tabs.setZoom(tabId, callback(factor));
});
});
};

// These are commands which are bound to keystrokes which must be handled by the background page.
// They are mapped in commands.coffee.
const BackgroundCommands = {
Expand Down Expand Up @@ -260,6 +268,17 @@ const BackgroundCommands = {
toggleMuteTab,
moveTabLeft: moveTab,
moveTabRight: moveTab,
zoomIn({ tabId, count }) {
const step = Settings.get("zoomStep");
setZoom(tabId, (factor) => factor + step * count);
},
zoomOut({ tabId, count }) {
const step = Settings.get("zoomStep");
setZoom(tabId, (factor) => factor - step * count);
},
zoomReset({ tabId }) {
setZoom(tabId, () => 1.0);
},

async nextFrame({ count, tabId }) {
// We're assuming that these frames are returned in the order that they appear on the page. This
Expand Down
1 change: 1 addition & 0 deletions lib/settings.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// WIP rewrite of settings.js
const defaultOptions = {
scrollStepSize: 60,
zoomStep: 0.10,
smoothScroll: true,
keyMappings: "# Insert your preferred key mappings here.",
linkHintCharacters: "sadfjklewcmpgh",
Expand Down
5 changes: 5 additions & 0 deletions pages/options.css
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ input#scrollStepSize {
margin-right: 3px;
padding-left: 3px;
}
input#zoomStep {
width: 70px;
margin-right: 3px;
padding-left: 3px;
}
textarea#userDefinedLinkHintCss, textarea#keyMappings, textarea#searchEngines {
width: 100%;;
min-height: 140px;
Expand Down
11 changes: 11 additions & 0 deletions pages/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@
<input id="scrollStepSize" type="number" />px
</td>
</tr>
<tr>
<td class="caption">Zoom step</td>
<td>
<div class="help">
<div class="example">
Factor to increment by when zooming in or out.
</div>
</div>
<input id="zoomStep" type="number" min="0.01" max="1.00" step="0.01" />
</td>
</tr>
<tr id="linkHintCharactersContainer">
<td class="caption">Characters used<br /> for link hints</td>
<td verticalAlign="top">
Expand Down
1 change: 1 addition & 0 deletions pages/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const options = {
regexFindMode: "boolean",
ignoreKeyboardLayout: "boolean",
scrollStepSize: "number",
zoomStep: "number",
smoothScroll: "boolean",
grabBackFocus: "boolean",
searchEngines: "string",
Expand Down