Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

feat(electron): switch to next/previous tab with Ctrl+Tab/Ctrl+Shift+Tab (#7943)

pengx17592150638eb3
diff --git a/packages/frontend/electron/src/main/application-menu/create.ts b/packages/frontend/electron/src/main/application-menu/create.ts
index 016dac844c..c85fe1db98 100644
--- a/packages/frontend/electron/src/main/application-menu/create.ts
+++ b/packages/frontend/electron/src/main/application-menu/create.ts
@@ -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();
+ },
+ },
],
},
{
diff --git a/packages/frontend/electron/src/main/windows-manager/tab-views.ts b/packages/frontend/electron/src/main/windows-manager/tab-views.ts
index a5e23a33a2..591d9044e3 100644
--- a/packages/frontend/electron/src/main/windows-manager/tab-views.ts
+++ b/packages/frontend/electron/src/main/windows-manager/tab-views.ts
@@ -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);
+ }
+};