fix(chat): do not hijack ctrl/cmd+digit while typing in an input (Fixes #2503) (#2689)

fix(chat): do not hijack ctrl/cmd+digit while typing in an input (Fixes #2503)
This commit is contained in:
Bohdan Triapitsyn
2026-08-28 23:45:57 +03:00
committed by GitHub
2 changed files with 22 additions and 1 deletions
@@ -1,6 +1,10 @@
import { expect, test } from 'bun:test';
import { Window } from 'happy-dom';
import { hasOpenDropdown, shouldStopDropdownImeEscape } from './keyboard-shortcut-dom';
import { hasOpenDropdown, isEditableEventTarget, shouldStopDropdownImeEscape } from './keyboard-shortcut-dom';
const domWindow = new Window();
Object.assign(globalThis, { document: domWindow.document, HTMLElement: domWindow.HTMLElement });
test('does not treat an unrelated visible listbox as an open dropdown', () => {
const promptNavigator = {} as Element;
@@ -35,3 +39,19 @@ test('stops IME Escape before an open dropdown dismiss listener', () => {
expect(shouldStopDropdownImeEscape({ key: 'Escape', isComposing: false, keyCode: 27 }, true)).toBe(false);
expect(shouldStopDropdownImeEscape({ key: 'Escape', isComposing: true, keyCode: 0 }, false)).toBe(false);
});
test('treats inputs, textareas, selects, and contenteditable elements as editable targets', () => {
expect(isEditableEventTarget(document.createElement('input'))).toBe(true);
expect(isEditableEventTarget(document.createElement('textarea'))).toBe(true);
expect(isEditableEventTarget(document.createElement('select'))).toBe(true);
const editableDiv = document.createElement('div');
Object.defineProperty(editableDiv, 'isContentEditable', { value: true });
expect(isEditableEventTarget(editableDiv)).toBe(true);
});
test('does not treat a plain element or non-element target as editable', () => {
expect(isEditableEventTarget(document.createElement('div'))).toBe(false);
expect(isEditableEventTarget(document.createElement('button'))).toBe(false);
expect(isEditableEventTarget(null)).toBe(false);
});
@@ -493,6 +493,7 @@ export const useKeyboardShortcuts = () => {
&& !event.repeat
&& eventMatchesShortcutPrefix(event, switchSurfacePrefix, heldKeysRef.current)
) {
if (isEditableEventTarget(event.target)) return;
const state = useUIStore.getState();
if (!state.isMobile && effectiveDirectory) {
const directory = normalizeContextPanelDirectoryKey(effectiveDirectory);