mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
feat(electron): switch to next/previous tab with Ctrl+Tab/Ctrl+Shift+Tab (#7943)
fix PD-1569
This commit is contained in:
@@ -11,6 +11,8 @@ import {
|
||||
showDevTools,
|
||||
showMainWindow,
|
||||
switchTab,
|
||||
switchToNextTab,
|
||||
switchToPreviousTab,
|
||||
undoCloseTab,
|
||||
} from '../windows-manager';
|
||||
import { applicationMenuSubjects } from './subject';
|
||||
@@ -152,6 +154,52 @@ export function createApplicationMenu() {
|
||||
visible: false,
|
||||
};
|
||||
}),
|
||||
{
|
||||
label: 'Switch to next tab',
|
||||
accelerator: 'CommandOrControl+Tab',
|
||||
click: () => {
|
||||
switchToNextTab();
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Switch to previous tab',
|
||||
accelerator: 'CommandOrControl+Shift+Tab',
|
||||
click: () => {
|
||||
switchToPreviousTab();
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Switch to next tab (mac)',
|
||||
accelerator: 'Command+]',
|
||||
visible: false,
|
||||
click: () => {
|
||||
switchToNextTab();
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Switch to previous tab (mac)',
|
||||
accelerator: 'Command+[',
|
||||
visible: false,
|
||||
click: () => {
|
||||
switchToPreviousTab();
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Switch to next tab (mac 2)',
|
||||
accelerator: 'Alt+Command+]',
|
||||
visible: false,
|
||||
click: () => {
|
||||
switchToNextTab();
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Switch to previous tab (mac 2)',
|
||||
accelerator: 'Alt+Command+[',
|
||||
visible: false,
|
||||
click: () => {
|
||||
switchToPreviousTab();
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -233,6 +233,12 @@ export class WebContentViewsManager {
|
||||
);
|
||||
}
|
||||
|
||||
get activeWorkbenchIndex() {
|
||||
return this.tabViewsMeta.workbenches.findIndex(
|
||||
w => w.id === this.activeWorkbenchId
|
||||
);
|
||||
}
|
||||
|
||||
get activeWorkbenchView() {
|
||||
return this.activeWorkbenchId
|
||||
? this.webViewsMap$.value.get(this.activeWorkbenchId)
|
||||
@@ -1023,3 +1029,27 @@ export const switchTab = (n: number) => {
|
||||
WebContentViewsManager.instance.showTab(item.id).catch(logger.error);
|
||||
}
|
||||
};
|
||||
|
||||
export const switchToNextTab = () => {
|
||||
const length =
|
||||
WebContentViewsManager.instance.tabViewsMeta.workbenches.length;
|
||||
const activeIndex = WebContentViewsManager.instance.activeWorkbenchIndex;
|
||||
const item = WebContentViewsManager.instance.tabViewsMeta.workbenches.at(
|
||||
activeIndex === length - 1 ? 0 : activeIndex + 1
|
||||
);
|
||||
if (item) {
|
||||
WebContentViewsManager.instance.showTab(item.id).catch(logger.error);
|
||||
}
|
||||
};
|
||||
|
||||
export const switchToPreviousTab = () => {
|
||||
const length =
|
||||
WebContentViewsManager.instance.tabViewsMeta.workbenches.length;
|
||||
const activeIndex = WebContentViewsManager.instance.activeWorkbenchIndex;
|
||||
const item = WebContentViewsManager.instance.tabViewsMeta.workbenches.at(
|
||||
activeIndex === 0 ? length - 1 : activeIndex - 1
|
||||
);
|
||||
if (item) {
|
||||
WebContentViewsManager.instance.showTab(item.id).catch(logger.error);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user