From ce6ccb5e4a7f88ee7c08e30425493fbe80c3bdf7 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sat, 1 Aug 2026 19:52:16 -0700 Subject: [PATCH] refactor(ime): share one candidate-digit predicate between the Linux guards The Linux candidate-state heuristic and the candidate key-release guard each carried their own copy of "unmodified ASCII digit", identical in behavior and free to drift apart. Only the predicate is shared; the two guards keep their separate windows and evidence, which are not the same thing. Co-authored-by: Orca --- .../terminal-ime-linux-candidate-state.ts | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/renderer/src/components/terminal-pane/terminal-ime-linux-candidate-state.ts b/src/renderer/src/components/terminal-pane/terminal-ime-linux-candidate-state.ts index 5594bcb3cbe..3e0f6942bdc 100644 --- a/src/renderer/src/components/terminal-pane/terminal-ime-linux-candidate-state.ts +++ b/src/renderer/src/components/terminal-pane/terminal-ime-linux-candidate-state.ts @@ -1,4 +1,5 @@ import type { XtermBypassEvent } from './xterm-bypass-policy' +import { isTerminalImeCandidateDigitKeyEvent } from './terminal-ime-candidate-key-release-guard' type TerminalImeLinuxCandidateState = { /** Classifies an event before the state observes it. */ @@ -21,7 +22,6 @@ type TerminalImeLinuxPhysicalKeyTracker = { const CANDIDATE_DIGIT_WINDOW_MS = 1500 const ASCII_LOWERCASE_LETTER = /^[a-z]$/ -const ASCII_DIGIT = /^[0-9]$/ const PHYSICAL_ASCII_LETTER_CODE = /^Key[A-Z]$/ const physicalKeyTrackers = new WeakMap< EventTarget, @@ -104,17 +104,6 @@ function isPlainAsciiLetterKey(event: XtermBypassEvent): boolean { ) } -/** Returns whether an event is an unmodified ASCII digit. */ -function isPlainAsciiDigitKey(event: XtermBypassEvent): boolean { - return ( - ASCII_DIGIT.test(event.key) && - !event.ctrlKey && - !event.altKey && - !event.metaKey && - !event.shiftKey - ) -} - /** Tracks legacy desktop Linux IME candidate-selection event sequences. */ export function createTerminalImeLinuxCandidateState( now: () => number = () => Date.now(), @@ -139,7 +128,9 @@ export function createTerminalImeLinuxCandidateState( const at = now() return { candidateDigitGuardActive: - event.type === 'keydown' && isPlainAsciiDigitKey(event) && candidateDigitUntil > at + event.type === 'keydown' && + isTerminalImeCandidateDigitKeyEvent(event) && + candidateDigitUntil > at } }, /** Records the current event after its classification is consumed. */ @@ -155,7 +146,7 @@ export function createTerminalImeLinuxCandidateState( } if (event.type === 'keydown') { - if (!isPlainAsciiDigitKey(event)) { + if (!isTerminalImeCandidateDigitKeyEvent(event)) { candidateDigitUntil = 0 } const physicalCode = event.code