From 2b7b8d526ea4a958bdcb258504cbdb8b4c2c92b1 Mon Sep 17 00:00:00 2001 From: 01zulfi <85733202+01zulfi@users.noreply.github.com> Date: Thu, 10 Apr 2025 10:51:40 +0500 Subject: [PATCH] web: don't close pinned tab on ctrl+w (#7805) * web: don't close pinned tab on ctrl+w Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com> * web: focus previously activated tab if ctrl+w on pinned tab Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com> --- apps/web/src/common/key-map.ts | 12 ++++++++++-- apps/web/src/stores/editor-store.ts | 10 ++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/apps/web/src/common/key-map.ts b/apps/web/src/common/key-map.ts index 5fae830a1..f40d2ef39 100644 --- a/apps/web/src/common/key-map.ts +++ b/apps/web/src/common/key-map.ts @@ -97,8 +97,16 @@ const KEYMAP = [ }, { keys: ["ctrl+w", "command+w"], - description: "Close active tab", - action: () => useEditorStore.getState().closeActiveTab() + description: + "Close active tab or focus previously activated tab if active tab pinned", + action: () => { + const activeTab = useEditorStore.getState().getActiveTab(); + if (activeTab?.pinned) { + useEditorStore.getState().focusLastActiveTab(); + return; + } + useEditorStore.getState().closeActiveTab(); + } }, { keys: ["ctrl+shift+w", "command+shift+w"], diff --git a/apps/web/src/stores/editor-store.ts b/apps/web/src/stores/editor-store.ts index 284cfcd49..1561ee78e 100644 --- a/apps/web/src/stores/editor-store.ts +++ b/apps/web/src/stores/editor-store.ts @@ -850,6 +850,16 @@ class EditorStore extends BaseStore { return this.focusTab(tabs[index === 0 ? tabs.length - 1 : index - 1].id); }; + focusLastActiveTab = () => { + const history = useEditorStore.getState().history; + if (history.length < 2) return; + + const previousTab = history.at(-2); + if (!previousTab) return; + + useEditorStore.getState().focusTab(previousTab); + }; + goBack = async () => { const activeTabId = this.get().activeTabId; if (!activeTabId || !tabSessionHistory.canGoBack(activeTabId)) return;