Retype the typed prefix when accepting restores a capital in it - #920
Merged
Merged
Conversation
Accepting a suggestion never changed letters already typed, so "i" then "I'm" gave "i'm" and "lon" then "London" gave "london". When the word has a capital where a lowercase letter was typed, acceptance now backspaces the prefix and types the whole word, and the label reads as the text will. The prefix is text Switchify typed itself in the current window with no outside activity since; the executor refuses more than 32 deletions. A capital the person typed is kept, a word typed in capitals is never retyped, and when the case already matches nothing is deleted. Closes #912 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The worker checks for outside keyboard or mouse activity up to its reply, but the main process only re-checked the foreground window, so a keypress or click in the same window before injection could move the caret and have other text deleted. The activity epoch is now recorded when the suggestion is chosen and must be unchanged, with a healthy observer, before any deletion. The replace releases input on a failure part-way through, and tests cover that failure and the buffer edits queued after a retype. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
enaboapps
force-pushed
the
912-retype-prefix
branch
from
September 27, 2026 11:37
6d7ddfc to
67ee1ad
Compare
enaboapps
marked this pull request as ready for review
September 27, 2026 12:02
7 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #912. Stacked on #919; part of the casing plan in #914. The decision is recorded on the issue.
What changed
worker.rs: for each suggestion,restoredcompares the typed prefix with the same stretch of the word. Where the word has a capital and the person typed a lowercase letter, the capital is restored; a capital the person typed is kept. When that changes the prefix, the suggestion's label shows the restored word and its insert becomes "delete the prefix, type the whole word". Otherwise the insert is the suffix as before, with nothing deleted. A prefix typed in capitals is never retyped.Response::Insertcarriesbackspaces. In-process pipe message only; no persisted schema change.scan_executor.rs:prediction_textbecomesprediction_replace(backspaces, text). It keeps the existing guards (modifiers released, no drag, no switch session, 64-character text limit), refuses more than 32 deletions, releases held input, sends that many Backspace taps, then types. The logic lives in a genericreplace_textso tests use the fake injector.prediction/mod.rs: after a successful insert, the service queues the same Backspace edits before the appended text, so the worker's buffer matches the screen. The foreground checks before and after injection are unchanged.docs/word-prediction.mdreplaces the "never deletes text" promise with the bounded exception and its limits.Safety notes
Review follow-up
An independent review found the main process re-checked only the foreground window before deleting, not outside activity. A keypress or click in the same window between the worker's reply and injection could have moved the caret and had other text deleted. The activity epoch is now recorded when the suggestion is chosen and must be unchanged, with a healthy observer, before any deletion; appending without deleting keeps its existing checks. The replace also releases input on a failure part-way through. New tests cover that guard, typing failing after the deletion with no key left down, and the buffer edits queued after a retype. The docs note that the deletion assumes one Backspace removes one typed character.
Validation
Node 24.13.0, Rust 1.97.1, on this top of the stack:
npm run lint,npm test(244 Vitest tests and 5 Node tests) andnpm run buildpassed. No frontend files changed.cargo fmt --checkandcargo clippy --all-targets -D warningspassed.cargo testpassed: 571 tests, including new tests for the restore rule, the accept payload and the executor's delete-then-type sequence and limits.🤖 Generated with Claude Code