Commit e1b9f4645 for llama.cpp

commit e1b9f46453a9145b8b932761af7451b52e0d0a08
Author: Aleksander Grygier <aleksander.grygier@gmail.com>
Date:   Mon Nov 30 17:01:12 2026 +0100

    ui: close the active conversation tab with Cmd+W (#33152)

    With Conversation tabs on, the browser's close shortcut (Cmd+W on Apple
    platforms, Ctrl+W elsewhere) closes the active tab while other tabs are
    open. On the last tab, on pages without the tab strip and at phone
    width it is left to the browser, so it closes the window as before.

    It only takes effect where the browser hands the key to the page, such
    as an installed Safari web app; Shift+Cmd+X keeps working everywhere.

    Assisted-by: Claude (Fable 5.2)

diff --git a/ui/apps/chat/src/lib/enums/keyboard.enums.ts b/ui/apps/chat/src/lib/enums/keyboard.enums.ts
index 751fb22f6..d4f51431c 100644
--- a/ui/apps/chat/src/lib/enums/keyboard.enums.ts
+++ b/ui/apps/chat/src/lib/enums/keyboard.enums.ts
@@ -24,6 +24,7 @@ export enum KeyboardKey {
 	PAGE_UP = 'PageUp',
 	SPACE = ' ',
 	TAB = 'Tab',
+	W_LOWER = 'w',
 	X_LOWER = 'x',
 	X_UPPER = 'X'
 }
diff --git a/ui/apps/chat/src/lib/hooks/use-keyboard-shortcuts.svelte.ts b/ui/apps/chat/src/lib/hooks/use-keyboard-shortcuts.svelte.ts
index 7d39faa3f..f5566109c 100644
--- a/ui/apps/chat/src/lib/hooks/use-keyboard-shortcuts.svelte.ts
+++ b/ui/apps/chat/src/lib/hooks/use-keyboard-shortcuts.svelte.ts
@@ -1,6 +1,6 @@
-import { NEW_CHAT_TAB_ID } from '#lib/constants/index.ts';
 import { KeyboardKey } from '#lib/enums/index.ts';
-import { conversationsStore, settingsStore, tabsStore } from '#lib/stores/index.ts';
+import { conversationsStore, deviceStore, settingsStore, tabsStore } from '#lib/stores/index.ts';
+import { resolveTabTarget, resolveWindowCloseTab } from '#lib/utils/index.ts';
 import { page } from '$app/state';

 interface KeyboardShortcutsCallbacks {
@@ -73,14 +73,33 @@ export function useKeyboardShortcuts(callbacks: KeyboardShortcutsCallbacks) {

 			event.preventDefault();

-			const activeId =
-				page.params.id ?? (page.route.id === '/(chat)' ? NEW_CHAT_TAB_ID : undefined);
+			const activeId = resolveTabTarget(page);

 			if (activeId) {
 				void tabsStore.close(activeId, true);
 			}
 		}

+		// the browser's own close shortcut: Cmd+W on Apple platforms, where Ctrl+W
+		// deletes a word in text fields, and Ctrl+W elsewhere
+		const isWindowClose =
+			(deviceStore.isApplePlatform ? event.metaKey && !event.ctrlKey : event.ctrlKey) &&
+			!event.shiftKey &&
+			!event.altKey &&
+			event.key === KeyboardKey.W_LOWER;
+
+		// the tab strip is hidden on mobile, where the shortcut keeps closing the window
+		if (isWindowClose && settingsStore.config.conversationTabs && !deviceStore.isMobile) {
+			if (event.defaultPrevented) return;
+
+			const tabId = resolveWindowCloseTab(page, tabsStore.openTabs);
+
+			if (tabId) {
+				event.preventDefault();
+				void tabsStore.close(tabId, true);
+			}
+		}
+
 		if (
 			isCmdOrCtrl &&
 			event.shiftKey &&
diff --git a/ui/apps/chat/src/lib/stores/device.svelte.ts b/ui/apps/chat/src/lib/stores/device.svelte.ts
index 4ca98e12a..dd034ec43 100644
--- a/ui/apps/chat/src/lib/stores/device.svelte.ts
+++ b/ui/apps/chat/src/lib/stores/device.svelte.ts
@@ -2,7 +2,7 @@
  * deviceStore - Browser environment signals
  *
  * Device capabilities, OS theme and viewport in one class store:
- * deviceStore.isMobile, deviceStore.isIOSDevice / isIOSSafari / isWKWebView /
+ * deviceStore.isMobile, deviceStore.isApplePlatform / isIOSDevice / isIOSSafari / isWKWebView /
  * isStandalone, deviceStore.systemTheme.isDark.
  *
  * UA-derived flags are static for the session; isStandalone and systemTheme
@@ -30,6 +30,8 @@ const UA_PATTERNS = {
 } as const;

 class DeviceStore {
+	/** macOS, iOS or iPadOS, where shortcuts take Cmd instead of Ctrl. */
+	readonly isApplePlatform: boolean = false;
 	/** Any iOS/iPadOS device, regardless of which app or browser embeds the page. */
 	readonly isIOSDevice: boolean = false;
 	/** The Safari browser app on iOS, excluding other iOS browsers and WKWebViews. */
@@ -63,6 +65,7 @@ class DeviceStore {

 		this.isIOSDevice =
 			UA_PATTERNS.IOS_PHONE.test(ua) || (UA_PATTERNS.MACINTOSH.test(ua) && isTouch);
+		this.isApplePlatform = this.isIOSDevice || UA_PATTERNS.MACINTOSH.test(ua);
 		// Safari keeps 'Safari/' in the UA; non-Safari iOS browsers emit their own
 		// token instead. WKWebView typically omits 'Safari/' entirely.
 		const hasSafariToken = UA_PATTERNS.SAFARI.test(ua) && !UA_PATTERNS.WEBVIEW_IOS.test(ua);
diff --git a/ui/apps/chat/src/lib/utils/chat-tabs.ts b/ui/apps/chat/src/lib/utils/chat-tabs.ts
index 6d0934301..f080e42ed 100644
--- a/ui/apps/chat/src/lib/utils/chat-tabs.ts
+++ b/ui/apps/chat/src/lib/utils/chat-tabs.ts
@@ -36,3 +36,13 @@ export function resolveTabView(page: TabRoute, openTabs: string[]): TabView {
 		ids: openTabs
 	};
 }
+
+/**
+ * Tab the browser's close shortcut closes in place of the window: the active
+ * one, while other tabs stay open. Null leaves the shortcut to the browser.
+ */
+export function resolveWindowCloseTab(page: TabRoute, openTabs: string[]): string | null {
+	const { activeId, ids } = resolveTabView(page, openTabs);
+
+	return activeId && ids.length > 1 && ids.includes(activeId) ? activeId : null;
+}
diff --git a/ui/apps/chat/src/lib/utils/index.ts b/ui/apps/chat/src/lib/utils/index.ts
index f4e17836d..ed7d04d70 100644
--- a/ui/apps/chat/src/lib/utils/index.ts
+++ b/ui/apps/chat/src/lib/utils/index.ts
@@ -255,7 +255,7 @@ export {
 	type PathQuery
 } from './working-directory';

-export { resolveTabTarget, resolveTabView, type TabView } from './chat-tabs';
+export { resolveTabTarget, resolveTabView, resolveWindowCloseTab, type TabView } from './chat-tabs';

 // Shared `file_glob_search` runner with a short-lived result cache
 export { runFolderSearch, runGlobSearch, runGlobSearchWithChildren } from './glob-search';
diff --git a/ui/apps/chat/tests/unit/chat-tabs.test.ts b/ui/apps/chat/tests/unit/chat-tabs.test.ts
new file mode 100644
index 000000000..c3c8b5764
--- /dev/null
+++ b/ui/apps/chat/tests/unit/chat-tabs.test.ts
@@ -0,0 +1,26 @@
+import { NEW_CHAT_TAB_ID } from '#lib/constants/index.ts';
+import { resolveWindowCloseTab } from '#lib/utils/chat-tabs.ts';
+import { describe, expect, it } from 'vitest';
+
+const chatPage = (id: string) => ({ params: { id }, route: { id: '/(chat)/chat/[id]' } });
+const newChatPage = { params: {}, route: { id: '/(chat)' } };
+const settingsPage = { params: {}, route: { id: '/settings' } };
+
+describe('resolveWindowCloseTab', () => {
+	it('closes the active tab while other tabs stay open', () => {
+		expect(resolveWindowCloseTab(chatPage('a'), ['a', 'b'])).toBe('a');
+		expect(resolveWindowCloseTab(newChatPage, ['a', NEW_CHAT_TAB_ID])).toBe(NEW_CHAT_TAB_ID);
+	});
+
+	it('leaves the shortcut to the browser on the last tab', () => {
+		expect(resolveWindowCloseTab(chatPage('a'), ['a'])).toBeNull();
+	});
+
+	it('leaves the shortcut to the browser on a page without tabs', () => {
+		expect(resolveWindowCloseTab(settingsPage, ['a', 'b'])).toBeNull();
+	});
+
+	it('leaves the shortcut to the browser when the route has no tab', () => {
+		expect(resolveWindowCloseTab(chatPage('c'), ['a', 'b'])).toBeNull();
+	});
+});