Skip to content

Commit 679497e

Browse files
committed
web: focus previously activated tab if ctrl+w on pinned tab
Signed-off-by: 01zulfi <[email protected]>
1 parent 3c19363 commit 679497e

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

apps/web/src/common/key-map.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,14 @@ const KEYMAP = [
9797
},
9898
{
9999
keys: ["ctrl+w", "command+w"],
100-
description: "Close active tab",
100+
description:
101+
"Close active tab or focus previously activated tab if active tab pinned",
101102
action: () => {
102103
const activeTab = useEditorStore.getState().getActiveTab();
103-
if (activeTab?.pinned) return;
104+
if (activeTab?.pinned) {
105+
useEditorStore.getState().focusPreviouslyActivatedTab();
106+
return;
107+
}
104108
useEditorStore.getState().closeActiveTab();
105109
}
106110
},

apps/web/src/stores/editor-store.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,16 @@ class EditorStore extends BaseStore<EditorStore> {
850850
return this.focusTab(tabs[index === 0 ? tabs.length - 1 : index - 1].id);
851851
};
852852

853+
focusPreviouslyActivatedTab = () => {
854+
const history = useEditorStore.getState().history;
855+
if (history.length < 2) return;
856+
857+
const previousTab = history.at(-2);
858+
if (!previousTab) return;
859+
860+
useEditorStore.getState().focusTab(previousTab);
861+
};
862+
853863
goBack = async () => {
854864
const activeTabId = this.get().activeTabId;
855865
if (!activeTabId || !tabSessionHistory.canGoBack(activeTabId)) return;

0 commit comments

Comments
 (0)