Skip to content

fix(terminal): prevent macOS dictation from duplicating text in the task terminal - #572

Open
binghaobhw wants to merge 1 commit into
cline:mainfrom
binghaobhw:fix/dictation-terminal-meta
Open

binghaobhw wants to merge 1 commit into
cline:mainfrom
binghaobhw:fix/dictation-terminal-meta

Conversation

@binghaobhw

@binghaobhw binghaobhw commented Jul 25, 2026 •

Copy link
Copy Markdown

Summary

Ending macOS dictation with the Command key delivers a bare Meta keydown while the dictation composition session is still active (isComposing: true). xterm's CompositionHelper.keydown treats any keydown outside its Shift/Ctrl/Alt/CapsLock/IME(229) exemption list as a real key interrupting the composition and eagerly flushes the composed text to the PTY; the subsequent compositionend then flushes the same text again — so every dictated phrase appeared twice in the terminal.

Captured trace (textarea events + WebSocket sends) showing the double flush:

[15918.6] WS-SEND " 嗯,哈喽哈喽"                        ← eager flush
[15918.9] keydown key="Meta" keyCode=93 isComposing=true  ← Cmd pressed to end dictation
[16166.8] compositionend data=" 嗯,哈喽哈喽"
[16167.4] WS-SEND " 嗯,哈喽哈喽"                        ← second flush, identical

The fix swallows bare Meta presses in attachCustomKeyEventHandler, which runs before xterm's composition handling. A lone Meta press has no meaning to a terminal, and combo shortcuts (Cmd+C / Cmd+V) are unaffected because those events arrive keyed by the non-modifier key.

The underlying defect (Meta missing from the modifier exemptions) will also be reported upstream to xtermjs/xterm.js.

fixes #566

Test plan

  • Manually verified on macOS 12 + Chrome against a source build: dictating into the task terminal and ending with Cmd no longer duplicates the phrase; Cmd-based shortcuts still work; CJK IME typing unaffected (its candidate keys arrive as keyCode 229, already exempt)
  • npm run check passes (pre-commit hook: typecheck + fast tests)
  • No automated test: the behavior lives in the interaction between a real KeyboardEvent stream and xterm's internal CompositionHelper, which the existing test setup does not simulate

🤖 Generated with Claude Code

…ask terminal

Ending macOS dictation with the Command key delivers a bare Meta keydown
while the dictation composition session is still active. xterm's
CompositionHelper treats any keydown outside its Shift/Ctrl/Alt/CapsLock/
IME(229) exemption list as a real key interrupting the composition and
eagerly flushes the composed text to the PTY; the subsequent
compositionend then flushes the same text again, so every dictated
phrase appeared twice.

Swallow bare Meta presses in the custom key event handler, which runs
before xterm's composition handling. A lone Meta press has no meaning to
the terminal, and combo shortcuts (Cmd+C/Cmd+V) are unaffected because
they arrive keyed by the non-modifier key.

fixes cline#566
@greptile-apps

greptile-apps Bot commented Jul 25, 2026

Copy link
Copy Markdown

PR author is not in the allowed authors list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macOS dictation: dictated text is duplicated in the task terminal when pressing Cmd to end dictation

1 participant