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>
This commit is contained in:
01zulfi
2025-04-10 10:51:40 +05:00
committed by GitHub
parent 0cc33f7a81
commit 2b7b8d526e
2 changed files with 20 additions and 2 deletions

View File

@@ -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"],

View File

@@ -850,6 +850,16 @@ class EditorStore extends BaseStore<EditorStore> {
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;