From 8af6876510da4133f69909dcf1edf3ea98eb47bf Mon Sep 17 00:00:00 2001 From: kunsanglee <85242378+kunsanglee@users.noreply.github.com> Date: Mon, 3 Aug 2026 01:19:39 -0700 Subject: [PATCH] fix(terminal): distinguish IME Process keys from Enter Adapted from #11273 commits c690ee609, 506524085, and cc69fa7bf. --- .../terminal-ime-deferred-newline.test.ts | 20 ++++++++++++------- .../terminal-ime-deferred-newline.ts | 7 ++++++- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/renderer/src/components/terminal-pane/terminal-ime-deferred-newline.test.ts b/src/renderer/src/components/terminal-pane/terminal-ime-deferred-newline.test.ts index fe7860e35fe..3f42c98e923 100644 --- a/src/renderer/src/components/terminal-pane/terminal-ime-deferred-newline.test.ts +++ b/src/renderer/src/components/terminal-pane/terminal-ime-deferred-newline.test.ts @@ -325,6 +325,7 @@ describe('isTerminalImeProcessEnter', () => { const event = (overrides: Partial = {}) => ({ key: 'Process', + code: 'Enter', keyCode: 229, metaKey: false, ctrlKey: false, @@ -333,19 +334,24 @@ describe('isTerminalImeProcessEnter', () => { ...overrides }) as KeyboardEvent - it.each([{ shiftKey: true }, { shiftKey: false, ctrlKey: true }])( - 'recognizes a Windows IME modifier Enter reported as Process', - (modifiers) => { - expect(isTerminalImeProcessEnter(event(modifiers))).toBe(true) - } - ) + it.each([ + { shiftKey: true }, + { shiftKey: false, ctrlKey: true }, + { code: 'NumpadEnter' }, + { code: '' }, + { code: 'Unidentified' } + ])('recognizes a Windows IME modifier Enter reported as Process', (modifiers) => { + expect(isTerminalImeProcessEnter(event(modifiers))).toBe(true) + }) it.each([ { key: 'Enter' }, { keyCode: 13 }, { shiftKey: false }, { ctrlKey: true }, - { altKey: true } + { altKey: true }, + { code: 'KeyQ' }, + { code: 'ArrowLeft' } ])('rejects a non-IME or ambiguous Process key', (override) => { expect(isTerminalImeProcessEnter(event(override))).toBe(false) }) diff --git a/src/renderer/src/components/terminal-pane/terminal-ime-deferred-newline.ts b/src/renderer/src/components/terminal-pane/terminal-ime-deferred-newline.ts index 992ae182698..12b8a19cd33 100644 --- a/src/renderer/src/components/terminal-pane/terminal-ime-deferred-newline.ts +++ b/src/renderer/src/components/terminal-pane/terminal-ime-deferred-newline.ts @@ -107,11 +107,16 @@ export function getTerminalImeModifiedEnterKind( } export function isTerminalImeProcessEnter( - event: Pick + event: Pick< + KeyboardEvent, + 'key' | 'code' | 'keyCode' | 'metaKey' | 'ctrlKey' | 'altKey' | 'shiftKey' + > ): boolean { + const { code } = event return ( event.key === 'Process' && event.keyCode === 229 && + (!code || code === 'Unidentified' || code === 'Enter' || code === 'NumpadEnter') && getTerminalImeModifiedEnterKind(event) !== null ) }