From 722d0fe00a34c438d39a7353b833c5560e9e77fe Mon Sep 17 00:00:00 2001 From: dragonwocky Date: Thu, 12 Nov 2020 00:20:55 +1100 Subject: [PATCH] tabs focus properly --- mods/core/render.js | 68 ++++----------------------------------------- 1 file changed, 6 insertions(+), 62 deletions(-) diff --git a/mods/core/render.js b/mods/core/render.js index 8b44c4f..82731f3 100644 --- a/mods/core/render.js +++ b/mods/core/render.js @@ -166,68 +166,6 @@ module.exports = (store, __exports) => { this.$dragging = null; } }); - document.addEventListener('keyup', (event) => { - if (!electron.remote.getCurrentWindow().isFocused()) return; - const tabStore = () => store('e1692c29-475e-437b-b7ff-3eee872e1a42'); - if (tabStore().select_modifier) { - // switch between tabs via key modifier - const select_tab_modifier = { - ctrlKey: false, - metaKey: false, - altKey: false, - shiftKey: false, - ...toKeyEvent(tabStore().select_modifier), - }; - let triggered = true; - for (let prop in select_tab_modifier) - if (select_tab_modifier[prop] !== event[prop]) triggered = false; - if ( - triggered && - [ - '1', - '2', - '3', - '4', - '5', - '6', - '7', - '8', - '9', - 'ArrowRight', - 'ArrowLeft', - ].includes(event.key) - ) - this.selectTab(event.key); - } - if (tabStore().new_tab) { - // create/close tab keybindings - const new_tab_keybinding = { - ctrlKey: false, - metaKey: false, - altKey: false, - shiftKey: false, - ...toKeyEvent(tabStore().new_tab), - }; - let triggered = true; - for (let prop in new_tab_keybinding) - if (new_tab_keybinding[prop] !== event[prop]) triggered = false; - if (triggered) this.newTab(); - } - if (tabStore().close_tab) { - const close_tab_keybinding = { - ctrlKey: false, - metaKey: false, - altKey: false, - shiftKey: false, - ...toKeyEvent(tabStore().close_tab), - }; - let triggered = true; - for (let prop in close_tab_keybinding) - if (close_tab_keybinding[prop] !== event[prop]) triggered = false; - if (triggered && document.querySelector('.tab.current .close')) - document.querySelector('.tab.current .close').click(); - } - }); electron.ipcRenderer.on('enhancer:close-tab', (event, tab) => { this.closeTab(tab); }); @@ -270,6 +208,9 @@ module.exports = (store, __exports) => { webContents.goForward(); } }); + electronWindow.addListener('focus', (e) => { + this.views.current.$el().focus(); + }); } newTab(url = '', title = 'notion.so', animate = true) { @@ -728,6 +669,9 @@ module.exports = (store, __exports) => { ref: ($titlebar) => { this.$titlebar = $titlebar; }, + onClick: (e) => { + this.views.current.$el().focus(); + }, }, React.createElement('button', { id: 'open-enhancer-menu',