From 300f876a287df1ebd4b07bb4ec94f5622adb776c Mon Sep 17 00:00:00 2001 From: amv146 Date: Tue, 8 Feb 2022 20:06:32 -0800 Subject: [PATCH] Added Ctrl-Tab and Ctrl-Shift-Tab functionality --- repo/tabs/client.mjs | 12 +++++++++--- repo/tabs/mod.json | 12 ++++++++++++ repo/tabs/tab.cjs | 30 ++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/repo/tabs/client.mjs b/repo/tabs/client.mjs index 8f0960b..9373351 100644 --- a/repo/tabs/client.mjs +++ b/repo/tabs/client.mjs @@ -10,14 +10,14 @@ export default async function ({ web, electron }, db) { const newTabHotkey = await db.get(['new_tab']), closeTabHotkey = await db.get(['close_tab']), restoreTabHotkey = await db.get(['restore_tab']), - selectTabModifier = await db.get(['select_modifier']); + selectTabModifier = await db.get(['select_modifier']), + prevTabHotkey = await db.get(['prev_tab']), + nextTabHotkey = await db.get(['next_tab']); web.addHotkeyListener(newTabHotkey, () => { electron.sendMessageToHost('new-tab'); - console.log('new-tab'); }); web.addHotkeyListener(restoreTabHotkey, () => { electron.sendMessageToHost('restore-tab'); - console.log('restore-tab'); }); web.addHotkeyListener(closeTabHotkey, () => electron.sendMessageToHost('close-tab')); for (let i = 1; i < 10; i++) { @@ -25,6 +25,12 @@ export default async function ({ web, electron }, db) { electron.sendMessageToHost('select-tab', i); }); } + web.addHotkeyListener(prevTabHotkey, () => { + electron.sendMessageToHost('select-prev-tab') + }); + web.addHotkeyListener(nextTabHotkey, () => { + electron.sendMessageToHost('select-next-tab') + }); const breadcrumbSelector = '.notion-topbar > div > [class="notranslate"] > .notion-focusable:last-child', diff --git a/repo/tabs/mod.json b/repo/tabs/mod.json index 29dc614..0d3004b 100644 --- a/repo/tabs/mod.json +++ b/repo/tabs/mod.json @@ -62,6 +62,18 @@ "Super+Shift" ] }, + { + "type": "hotkey", + "key": "prev_tab", + "label": "previous tab hotkey", + "value": "Control+Shift+Tab" + }, + { + "type": "hotkey", + "key": "next_tab", + "label": "next tab hotkey", + "value": "Control+Tab" + }, { "type": "hotkey", "key": "new_tab", diff --git a/repo/tabs/tab.cjs b/repo/tabs/tab.cjs index 76cf622..4e44cc0 100644 --- a/repo/tabs/tab.cjs +++ b/repo/tabs/tab.cjs @@ -228,6 +228,36 @@ module.exports = async function (api, db, tabCache = new Map()) { const $tab = i === 9 ? this.$tabList.lastElementChild : this.$tabList.children[i - 1]; if ($tab) $tab.click(); }); + fromNotion('notion-enhancer:select-prev-tab', () => { + if (this.$tabList.count == 1) { + return; + } + const $sibling = this.$tab.previousElementSibling; + if ($sibling) { + $sibling.click(); + } + else { + let $tab = this.$tabList.lastElementChild; + if ($tab) { + $tab.click(); + } + } + }); + fromNotion('notion-enhancer:select-next-tab', () => { + if (this.$tabList.count == 1) { + return; + } + const $sibling = this.$tab.nextElementSibling; + if ($sibling) { + $sibling.click(); + } + else { + let $tab = this.$tabList.children[0] + if ($tab) { + $tab.click(); + } + } + }); } #firstQuery = true;