Skip to content

Commit

Permalink
add commands: zoomIn + zoomOut
Browse files Browse the repository at this point in the history
  • Loading branch information
gdh1995 committed Oct 26, 2019
1 parent f3a99fb commit ad5a094
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ __Other extensions supporting Vimium C:__
* Chrome: add a feature to hook in-page "access keys" and enable it by default
* Firefox: support 63+ and more conditions
* VHints: <kbd>Tab</kbd>: now only switch visibility in limited ranges
* add `zoomIn` and `zoomOut` commands, and use a huge count like `1111` to reset zoom
([#83](https://github.com/gdh1995/vimium-c/issues/83), [philc#2978](https://github.com/philc/vimium/pull/2978))
* fix some old bugs

1.78.3
Expand Down
6 changes: 6 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,12 @@
"visitPreviousTab": {
"message": "Go to previously-visited tab on current window"
},
"zoomIn": {
"message": "Make a current tab zoom in"
},
"zoomOut": {
"message": "Make a current tab zoom out"
},
"createTab_s": {
"message": "Create new tab"
},
Expand Down
6 changes: 6 additions & 0 deletions _locales/zh/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,12 @@
"visitPreviousTab": {
"message": "切换到最近访问的上一个标签页"
},
"zoomIn": {
"message": "放大网页"
},
"zoomOut": {
"message": "缩小网页"
},
"createTab_s": {
"message": "打开新的标签页"
},
Expand Down
4 changes: 3 additions & 1 deletion background/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,9 @@ availableCommands_: { __proto__: null as never,
toggleVomnibarStyle: [ kBgCmd.toggleVomnibarStyle, 1, 1, { style: "dark" } ],
closeDownloadBar: [ kBgCmd.moveTabToNewWindow, 1, 1, { all: 1 } ],
showTip: [ kBgCmd.showTip, 1, 1 ],
visitPreviousTab: [ kBgCmd.visitPreviousTab, 1, 0 ]
visitPreviousTab: [ kBgCmd.visitPreviousTab, 1, 0 ],
zoomIn: [ kBgCmd.toggleZoom, 1, 0 ],
zoomOut: [ kBgCmd.toggleZoom, 1, 0, { count: -1 } ],
} as ReadonlySafeDict<CommandsNS.Description>
},
CommandsData_: CommandsDataTy = CommandsData_ as never || {
Expand Down
2 changes: 1 addition & 1 deletion background/help_dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ var HelpDialog = {
, "scrollToBottom", "scrollToLeft", "scrollToRight", "scrollPageDown", "scrollPageUp"
, "scrollPxDown", "scrollPxUp", "scrollPxLeft", "scrollPxRight"
, "scrollFullPageDown", "scrollFullPageUp", "reload", "reloadTab", "reloadGivenTab"
, "toggleViewSource"
, "zoomIn", "zoomOut", "toggleViewSource"
, "copyCurrentUrl", "copyCurrentTitle", "switchFocus", "simBackspace"
, "LinkHints.activateModeToCopyLinkUrl", "LinkHints.activateModeToCopyLinkText"
, "openCopiedUrlInCurrentTab", "openCopiedUrlInNewTab", "goUp", "goToRoot"
Expand Down
38 changes: 37 additions & 1 deletion background/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,8 @@
UseTab.CurWndTabs, UseTab.NoTab, UseTab.CurWndTabs, UseTab.NoTab, UseTab.ActiveTab,
UseTab.ActiveTab, UseTab.NoTab, UseTab.CurWndTabs, UseTab.NoTab,
UseTab.CurWndTabs, UseTab.NoTab, UseTab.NoTab,
UseTab.ActiveTab, UseTab.NoTab, UseTab.ActiveTab, UseTab.ActiveTab, UseTab.NoTab, UseTab.NoTab
UseTab.ActiveTab, UseTab.NoTab, UseTab.ActiveTab, UseTab.ActiveTab, UseTab.NoTab, UseTab.NoTab,
UseTab.NoTab
],
BackgroundCommands: {
[K in kBgCmd & number]:
Expand Down Expand Up @@ -1882,6 +1883,41 @@
keyword: cOptions.keyword,
});
BackgroundCommands[kBgCmd.openUrl]();
},
/* kBgCmd.toggleZoom: */ function (this: void): void {
if (Build.BTypes & BrowserType.Edge && (!(Build.BTypes & ~BrowserType.Edge) || OnOther === BrowserType.Edge)) {
Backend_.complain_("control zoom settings of tabs");
return;
}
if (Build.BTypes & BrowserType.Chrome && Build.MinCVer < BrowserVer.Min$Tabs$$setZoom
&& CurCVer_ < BrowserVer.Min$Tabs$$setZoom) {
Backend_.showHUD_(`Vimium C can not control zoom settings before Chrome ${BrowserVer.Min$Tabs$$setZoom}`);
return;
}
chrome.tabs.getZoom(curZoom => {
if (!curZoom) { return onRuntimeError(); }
cRepeat < -4 && (cRepeat = -cRepeat);
let newZoom = curZoom, m = Math;
if (cRepeat > 4) {
newZoom = cRepeat / (cRepeat > 1000 ? cRepeat : cRepeat > 49 ? 100 : 10);
newZoom = !(Build.BTypes & ~BrowserType.Firefox)
|| Build.BTypes & BrowserType.Firefox && OnOther === BrowserType.Firefox
? m.max(0.3, m.min(newZoom, 3)) : m.max(0.25, m.min(newZoom, 5));
} else {
let nearest = 0, delta = 9,
steps = !(Build.BTypes & ~BrowserType.Firefox)
|| Build.BTypes & BrowserType.Firefox && OnOther === BrowserType.Firefox
? [0.3, 0.5, 0.67, 0.8, 0.9, 1, 1.1, 1.2, 1.33, 1.5, 1.7, 2, 2.4, 3]
: [0.25, 1 / 3, 0.5, 2 / 3, 0.75, 0.8, 0.9, 1, 1.1, 1.25, 1.5, 1.75, 2, 2.5, 3, 4, 5];
for (let ind = 0, d2 = 0; ind < steps.length && (d2 = m.abs(steps[ind] - curZoom)) < delta; ind++) {
nearest = ind; delta = d2;
}
newZoom = steps[nearest + cRepeat < 0 ? 0 : m.min(nearest + cRepeat, steps.length - 1)];
}
if (m.abs(newZoom - curZoom) > 0.005) {
chrome.tabs.setZoom(newZoom);
}
});
}
],
numHeadRe = <RegExpOne> /^-?\d+|^-/;
Expand Down
2 changes: 1 addition & 1 deletion types/messages.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ declare const enum kBgCmd {
goToRoot, goUp, moveTab, mainFrame,
visitPreviousTab, copyTabInfo, clearFindHistory,
toggleViewSource, clearMarks, toggleVomnibarStyle,
goBackFallback, showTip, autoOpenFallback,
goBackFallback, showTip, autoOpenFallback, toggleZoom,
END = "END",
}

Expand Down
1 change: 1 addition & 0 deletions types/vimium_c.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ declare const enum BrowserVer {
// before 42, event.path is a simple NodeList instance ; even if EXPERIMENTAL or LEGACY
Min$Event$$path$IsStdArrayAndIncludesWindow = 42,
Min$Tabs$$getZoom = 42,
Min$Tabs$$setZoom = 42,
Min$EnableSitePerProcess$Flag = 42,
MinParentNodeGetterInNodePrototype = 42, // also .childNodes; even if even if EXPERIMENTAL or LEGACY
MinEnsured$fetch = 42, // even if LEGACY; can not fetch chrome-extension:// before C47
Expand Down

1 comment on commit ad5a094

@gdh1995
Copy link
Owner Author

Choose a reason for hiding this comment

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

For #83 .

Please sign in to comment.