tabs focus properly

This commit is contained in:
dragonwocky 2020-11-12 00:20:55 +11:00
parent c067d93a74
commit 722d0fe00a
Signed by: dragonwocky
GPG Key ID: C7A48B7846AA706D

View File

@ -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',