Commit 28de970cc for llama.cpp

commit 28de970cc17f3a64e58db5dd9a238bb2c8513069
Author: Aleksander Grygier <aleksander.grygier@gmail.com>
Date:   Fri Nov 20 14:01:50 2026 +0100

    ui : focus the chat form when typing with nothing focused (#32570)

    A printable key pressed on the chat screen while no field, editor,
    dialog or menu has focus now moves focus to the chat form, and the
    character lands there.

    Assisted-by: Claude (Opus 5.5 Medium)

diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatScreen/ChatScreenForm.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatScreen/ChatScreenForm.svelte
index 309cb7222..21bd62201 100644
--- a/ui/apps/chat/src/lib/components/app/chat/ChatScreen/ChatScreenForm.svelte
+++ b/ui/apps/chat/src/lib/components/app/chat/ChatScreen/ChatScreenForm.svelte
@@ -3,7 +3,7 @@
 	import { SETTINGS_KEYS } from '#lib/constants/index.ts';
 	import { useDraftMessages } from '#lib/hooks/use-draft-messages.svelte.ts';
 	import { deviceStore, settingsStore } from '#lib/stores/index.ts';
-	import { hapticTap } from '#lib/utils/index.ts';
+	import { hapticTap, shouldTypeToFocus } from '#lib/utils/index.ts';
 	import { afterNavigate } from '$app/navigation';
 	import { page } from '$app/state';
 	import { onMount, tick } from 'svelte';
@@ -127,6 +127,14 @@
 		chatFormRef?.focus();
 	}

+	// Typing while nothing takes text starts the message: focused during keydown, the
+	// character the key types lands in the form
+	function handleWindowKeydown(event: KeyboardEvent) {
+		if (disabled || deviceStore.isMobile || !shouldTypeToFocus(event)) return;
+
+		chatFormRef?.focus();
+	}
+
 	onMount(() => {
 		if (!deviceStore.isMobile) {
 			setTimeout(focusFormUnlessCaptured, 100);
@@ -148,6 +156,8 @@
 	});
 </script>

+<svelte:window onkeydown={handleWindowKeydown} />
+
 <div bind:this={formWrapperEl} class="chat-screen-form-wrapper">
 	<ChatForm
 		bind:this={chatFormRef}
diff --git a/ui/apps/chat/src/lib/utils/index.ts b/ui/apps/chat/src/lib/utils/index.ts
index a05445513..61c202ab0 100644
--- a/ui/apps/chat/src/lib/utils/index.ts
+++ b/ui/apps/chat/src/lib/utils/index.ts
@@ -108,6 +108,7 @@ export {

 // IME utilities
 export { isIMEComposing } from './is-ime-composing';
+export { shouldTypeToFocus } from './type-to-focus';

 // LaTeX utilities
 export { maskInlineLaTeX, preprocessLaTeX } from './latex-protection';
diff --git a/ui/apps/chat/src/lib/utils/type-to-focus.ts b/ui/apps/chat/src/lib/utils/type-to-focus.ts
new file mode 100644
index 000000000..22ffc3a56
--- /dev/null
+++ b/ui/apps/chat/src/lib/utils/type-to-focus.ts
@@ -0,0 +1,28 @@
+import { isIMEComposing } from './is-ime-composing';
+
+const EDITABLE_SELECTOR =
+	'input, textarea, select, [contenteditable]:not([contenteditable="false"])';
+// widgets that take typed letters themselves (typeahead) or trap focus
+const KEY_CAPTURING_SELECTOR =
+	'[role="dialog"], [role="alertdialog"], [role="menu"], [role="listbox"]';
+
+/**
+ * Whether a keypress should move focus to the chat form so the character lands there:
+ * a printable key typed while nothing that takes text has focus.
+ */
+export function shouldTypeToFocus(event: KeyboardEvent): boolean {
+	if (event.defaultPrevented || event.ctrlKey || event.metaKey || event.altKey) return false;
+
+	if (isIMEComposing(event)) return false;
+
+	// a single character, not a named key; whitespace keeps scrolling or pressing the focused button
+	if (event.key.length !== 1 || event.key.trim() === '') return false;
+
+	const active = document.activeElement;
+
+	if (active instanceof HTMLElement && active !== document.body) {
+		if (active.closest(EDITABLE_SELECTOR) || active.closest(KEY_CAPTURING_SELECTOR)) return false;
+	}
+
+	return true;
+}
diff --git a/ui/apps/chat/tests/client/type-to-focus.svelte.test.ts b/ui/apps/chat/tests/client/type-to-focus.svelte.test.ts
new file mode 100644
index 000000000..b4a82585d
--- /dev/null
+++ b/ui/apps/chat/tests/client/type-to-focus.svelte.test.ts
@@ -0,0 +1,72 @@
+import { shouldTypeToFocus } from '#lib/utils/type-to-focus.ts';
+import { afterEach, describe, expect, it } from 'vitest';
+
+function key(key: string, init: KeyboardEventInit = {}) {
+	return new KeyboardEvent('keydown', { bubbles: true, cancelable: true, key, ...init });
+}
+
+function mount(html: string) {
+	const host = document.createElement('div');
+
+	host.innerHTML = html;
+	document.body.appendChild(host);
+
+	return host;
+}
+
+describe('shouldTypeToFocus', () => {
+	afterEach(() => {
+		(document.activeElement as HTMLElement | null)?.blur();
+		document.body.innerHTML = '';
+	});
+
+	it('takes a printable key when nothing has focus', () => {
+		expect(shouldTypeToFocus(key('a'))).toBe(true);
+		expect(shouldTypeToFocus(key('A', { shiftKey: true }))).toBe(true);
+		expect(shouldTypeToFocus(key('?'))).toBe(true);
+	});
+
+	it('takes a printable key while a button has focus', () => {
+		mount('<button>Copy</button>').querySelector('button')!.focus();
+
+		expect(shouldTypeToFocus(key('h'))).toBe(true);
+	});
+
+	it('leaves named keys, whitespace and shortcuts alone', () => {
+		for (const name of ['Enter', 'Escape', 'Tab', 'ArrowDown', 'F5', ' ']) {
+			expect(shouldTypeToFocus(key(name))).toBe(false);
+		}
+
+		expect(shouldTypeToFocus(key('k', { metaKey: true }))).toBe(false);
+		expect(shouldTypeToFocus(key('k', { ctrlKey: true }))).toBe(false);
+		expect(shouldTypeToFocus(key('k', { altKey: true }))).toBe(false);
+	});
+
+	it('leaves keys another handler already took', () => {
+		const event = key('a');
+
+		event.preventDefault();
+
+		expect(shouldTypeToFocus(event)).toBe(false);
+	});
+
+	it('leaves typing in a field or editor where it is', () => {
+		const host = mount('<input /><textarea></textarea><div contenteditable="true">x</div>');
+
+		for (const el of host.querySelectorAll<HTMLElement>('input, textarea, [contenteditable]')) {
+			el.focus();
+			expect(shouldTypeToFocus(key('a'))).toBe(false);
+		}
+	});
+
+	it('leaves keys inside dialogs and menus', () => {
+		const host = mount(
+			'<div role="dialog"><button>OK</button></div><div role="menu"><button role="menuitem">Rename</button></div>'
+		);
+
+		for (const button of host.querySelectorAll('button')) {
+			button.focus();
+			expect(shouldTypeToFocus(key('r'))).toBe(false);
+		}
+	});
+});