Skip to content

fix(terminal): avoid resending input after Gboard replacements - #2789

Merged
devswha merged 3 commits into
devswha:mainfrom
zs311521:fix/terminal-input-composition-resend
Nov 5, 2026
Merged

devswha merged 3 commits into
devswha:mainfrom
zs311521:fix/terminal-input-composition-resend

Conversation

@zs311521

@zs311521 zs311521 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Change

With Gboard's double-space period turned on, a second space after a word in Direct typing makes Gboard replace the trailing space with ". ". The terminal then received the whole input line again, so the line appeared twice.

The keyCode 229 fallback in the patched xterm CompositionHelper (patches/@xterm%[email protected]) took the change as newValue.replace(oldValue, ''). After the replacement the old value is no longer a substring of the new one, so the full new value was sent. The fallback now keeps the common prefix, compared by code point so a surrogate pair is never split, and sends one DEL per removed character followed by the inserted text. For word word → word word. the terminal receives \x7f. . The server input path is unchanged.

scripts/xterm-composition.test.ts builds the patched helper with scripts/build-xterm.ts, as the Vite build does, and drives it with composition, insertText and insertReplacementText events: repeated sentence boundaries, two already inserted spaces, plain appends and a deletion, a supplementary character, an interrupting key, and reset.

Validation

On this branch, with Bun 1.4.4 and HERDR_TEST_MODE=unit:

  • bun test scripts/xterm-composition.test.ts: 7 pass. With the helper built from main's patch, 4 of the 7 fail (both double-space period cases, the two-spaces case and the supplementary character case).
  • bun test src/components/ComposerCrossTab.test.tsx src/components/ComposerRestored.test.tsx src/lib/useComposerSends.test.ts src/lib/terminalDraft.test.ts: 53 pass.
  • bun test server/core/input-line-send.test.ts server/herdr-core/attach-session.test.ts server/mirror-input.test.ts: 31 pass.
  • bun test scripts/xterm-parser-state.test.ts scripts/changelog-fold.test.ts scripts/conventions.test.ts: 35 pass, 1 skip.
  • bun run typecheck and bun run build: pass.

Not run: bun run check fast or full, and a check on a physical Android device with Gboard.

The keyCode 229 fallback in the patched xterm CompositionHelper took the
change as newValue.replace(oldValue, ''). When Gboard's double-space
period turns a trailing space into ". ", the old value is no longer a
substring of the new one, so the whole line was sent again.

Keep the shared prefix, compared by code point, and send one DEL for each
removed character followed by the inserted text. The server input path
is unchanged.

Add a regression test that drives composition, insertText and
insertReplacementText events through the patched xterm source, covering
repeated boundaries, two inserted spaces, a supplementary character, an
interrupting key and reset.
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: devswha/ovis
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: fda9c00
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2da4a654-085e-4036-b963-fe4006c95842

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes

    • Fixed an issue where Gboard’s double-space shortcut could repeat the terminal’s last input line.
    • Improved handling of composed text during paste, focus changes, dictation, and other keyboard input, including on Safari and iOS.
    • Improved Backspace behavior during text composition and screen-reader use.
    • Corrected small-delta mouse-wheel scrolling and Alt-key fast scrolling.
  • New Features

    • Added terminal methods for finishing text composition, setting input viewport bounds, and checking OSC string state.
    • Alt+arrow keys now send word-navigation sequences.

The patched xterm CompositionHelper textarea fallback now detects replacements by Unicode code point and sends the changed suffixes. Regression tests cover mobile composition edits, and a changelog entry describes the Gboard double-space period fix.

Changes: Composition replacement

Layer / File(s) Summary
Textarea replacement diff and regression coverage
patches/@xterm%[email protected], scripts/xterm-composition.test.ts, changelog.d/terminal-gboard-period.md
The fallback finds the common prefix by Unicode code point, sends deletes for the replaced suffix, and records the inserted suffix as already sent. Tests cover punctuation replacement, deletion, supplementary characters, adjacent compositions, and reset before deferred work. The changelog describes the Gboard double-space period fix.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Possibly related PRs

  • devswha/ovis#2335: Introduced the patched xterm.js 6.0.0 dependency that this change updates.
  • devswha/ovis#1850: Changed CompositionHelper replacement handling, which this change further updates.

Suggested reviewers: devswha

Merge Risk: Minimal · previous review e0651

The Gboard replacement fix has no identified blocker and appears mergeable subject to normal checks. Physical Android validation remains unreported.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title names the main change: a fix in the terminal that stops resending input after Gboard replacements. The raw summary and the PR description both describe the keyCode 229 fallback in the patche…
Description check Passed The description follows the template with its two required sections, Change and Validation. The Change section explains the problem (a repeated input line after Gboard's double-space period), the caus…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: a fix in the terminal that stops resending input after Gboard replacements. The raw summary and the PR description both describe the keyCode 229 fallback in the patched xterm CompositionHelper. The title is specific, under 72 characters, and uses the conventional fix(scope) form. It does not cover the test file or the other patch additions, which is expected.

Full details: Description check

Explanation

The description follows the template with its two required sections, Change and Validation. The Change section explains the problem (a repeated input line after Gboard's double-space period), the cause (the replace-based fallback), the fix (common-prefix diff by code point with DEL per removed character), and the expected result (\x7f. for the example). The Validation section lists the commands run with results and names the checks not run (check fast, check full, and a physical Android device test). The description does not state whether the change touches the HTTP/WS contract, so it is not fully complete on that point. It is mostly complete, so it passes.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 1 files. (2 skipped: 2 unsupported.)

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: devswha/ovis
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: b2d9e5d
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 739482de-b7b2-4cae-a7c4-f856bd47b135
Commits

Reviewing files that changed from the base of the PR and between b2d9e5d and e0651bb.

Files selected for processing: 3

  • changelog.d/terminal-gboard-period.md
  • patches/@xterm%[email protected]
  • scripts/xterm-composition.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

…ange

The common-prefix diff sent DEL for every character after the first
change. Two cases deleted text the user never edited:

- An edit before the end of the textarea (caret moved back) treated the
  untouched tail as removed. Such an edit now forwards only a plain
  insertion at the caret, with no DEL.
- Enter, Ctrl+C, Backspace, a paste or blur clear the textarea before
  the deferred diff runs, which then sent one DEL per character of the
  line. The next key, paste, blur or embedder input now sends the
  pending edit first.
@devswha

devswha commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Thanks @zs311521, the bug reproduces on main and the fix is right for it. I pushed one commit on top (be76723) after review, plus a merge of main:

  • An edit before the end of the textarea (caret moved back) no longer sends DEL for the untouched tail; it forwards only a plain insertion at the caret.
  • Enter, Ctrl+C, Backspace, a paste, blur or key bar input now send a pending 229 edit before the textarea is cleared, instead of the deferred diff sending one DEL per character of the line afterwards.
  • Three tests for these; they fail on the previous head and pass now.

Validation: bun run check fast passed (typecheck, build, 11305 unit tests). scripts/xterm-composition.test.ts: 10 pass; 4 of the original 7 fail on main.

Left as a follow-up (pre-existing limit of a textarea that cannot see the shell cursor): #2836

@devswha

devswha commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Thanks @zs311521 - the bug reproduced on main (Gboard's double-space period resent the whole line) and your tests caught it. We added a small maintainer commit on top for two edge cases Codex found (mid-line edits and a cleared textarea before the deferred diff), with tests. Merging. Two older cursor-sync limits are tracked in #2836.

Merge note: external fix; supply-chain check done (one xterm patch function, a test, a changelog fragment); bug reproduced; new tests fail on main; omo CLEAR at be76723; Codex Terra xhigh MEDIUMs fixed; required checks green; CodeRabbit skipped.

@devswha
devswha merged commit bc3821c into devswha:main Nov 5, 2026
16 checks passed
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.

2 participants