@@ -10,6 +10,7 @@ import {
|
|||||||
reloadView,
|
reloadView,
|
||||||
showDevTools,
|
showDevTools,
|
||||||
showMainWindow,
|
showMainWindow,
|
||||||
|
switchTab,
|
||||||
undoCloseTab,
|
undoCloseTab,
|
||||||
} from '../windows-manager';
|
} from '../windows-manager';
|
||||||
import { applicationMenuSubjects } from './subject';
|
import { applicationMenuSubjects } from './subject';
|
||||||
@@ -138,6 +139,22 @@ export function createApplicationMenu() {
|
|||||||
undoCloseTab().catch(console.error);
|
undoCloseTab().catch(console.error);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Switch to tab',
|
||||||
|
acceleratorWorksWhenHidden: true,
|
||||||
|
visible: false,
|
||||||
|
submenu: [1, 2, 3, 4, 5, 6, 7, 8, 9].map(n => {
|
||||||
|
const shortcut = `CommandOrControl+${n}`;
|
||||||
|
const listener = () => {
|
||||||
|
switchTab(n);
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
label: `Switch to tab ${n}`,
|
||||||
|
accelerator: shortcut,
|
||||||
|
click: listener,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { join } from 'node:path';
|
|||||||
import {
|
import {
|
||||||
app,
|
app,
|
||||||
type CookiesSetDetails,
|
type CookiesSetDetails,
|
||||||
globalShortcut,
|
|
||||||
type View,
|
type View,
|
||||||
type WebContents,
|
type WebContents,
|
||||||
WebContentsView,
|
WebContentsView,
|
||||||
@@ -700,27 +699,6 @@ export class WebContentViewsManager {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
app.on('ready', () => {
|
|
||||||
// bind CMD/CTRL+1~8 to switch tabs
|
|
||||||
// bind CMD/CTRL+9 to switch to the last tab
|
|
||||||
[1, 2, 3, 4, 5, 6, 7, 8, 9].forEach(n => {
|
|
||||||
const shortcut = `CommandOrControl+${n}`;
|
|
||||||
const listener = () => {
|
|
||||||
if (!this.mainWindow?.isFocused()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const item = this.tabViewsMeta.workbenches.at(n === 9 ? -1 : n - 1);
|
|
||||||
if (item) {
|
|
||||||
this.showTab(item.id).catch(logger.error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
globalShortcut.register(shortcut, listener);
|
|
||||||
disposables.push({
|
|
||||||
unsubscribe: () => globalShortcut.unregister(shortcut),
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
app.on('before-quit', () => {
|
app.on('before-quit', () => {
|
||||||
disposables.forEach(d => d.unsubscribe());
|
disposables.forEach(d => d.unsubscribe());
|
||||||
});
|
});
|
||||||
@@ -1030,3 +1008,12 @@ export const pingAppLayoutReady = (wc: WebContents) => {
|
|||||||
WebContentViewsManager.instance.setTabUIReady(viewId);
|
WebContentViewsManager.instance.setTabUIReady(viewId);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const switchTab = (n: number) => {
|
||||||
|
const item = WebContentViewsManager.instance.tabViewsMeta.workbenches.at(
|
||||||
|
n === 9 ? -1 : n - 1
|
||||||
|
);
|
||||||
|
if (item) {
|
||||||
|
WebContentViewsManager.instance.showTab(item.id).catch(logger.error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user