Repository navigation
Conversation
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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. |
FuJacob
force-pushed
the
security/accept-only-shown-text
branch
from
November 23, 2026 04:12
080f317 to
5418970
Compare
This branch has not been deployed
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.
Summary
Tab could insert text the user had never seen in two ways. On a host that offers one row (single-line fields, a caret with text below it, no measured line pitch), the inline ghost paints only the head that fits and stops at a newline, but full acceptance (and phrase acceptance) inserted the whole buffered tail. A Tab pressed during post-exhaustion regeneration was queued and replayed as an accept of the next continuation in the same run-loop turn that continuation was first presented, or while the overlay was still holding it off screen for a caret read. Tab now inserts only text that has been painted.
SuggestionOverlayControlling.truncatedDisplayText(defaultnil):OverlayControllerreports the painted head when the presented inline layout is truncated (GhostTextLayout.isTruncated/remainingText). It readslifecycle.inlineSession, which exists only while an inline ghost is presented, so card mode and a hidden overlay report nothing. The coordinator reads this one value and never sees view code.SuggestionSessionReconciler:shownHead(of:overlayState:truncatedDisplayText:)re-bases the painted head onto the live tail (typed-through letters, an accept whose next present is still held, a held present that extends the painted one), andacceptanceChunk(_:limitedTo:)cuts a word, phrase or full-accept chunk back to it.SuggestionInteractionState.prepareAcceptance/prepareFullAcceptanceapply the cap through one shared step (limitingToShownHead) after the shared validation inprepare. The rest of the suggestion stays in the session and is shown by the existing partial-accept / advance path, so the next press takes it. I chose cap-and-continue over refusing because refusing would hand the key to the host and tear down the suggestion.SuggestionAcceptancePreparation.unshown: when none of the live tail has been painted yet (e.g. a capped accept took the whole head and the next present is held), the coordinator owns the key, inserts nothing, and keeps the session. It does not pass the key through, which would leak a focus-moving Tab (the case Keep rapid Tab accepts owned while the overlay holds its next present #838 fixed).PostExhaustionAcceptanceStatenow only swallows a press during the window (holdPressIfArmed,consumeHeldPress).flushQueuedPostExhaustionAcceptIfNeededis replaced byendPostExhaustionWindowForFreshSuggestion(still called at the end ofpresentFreshResult), which ends the window and logs a dropped press but never accepts. I kept swallowing as that press's fate rather than sending it to the host: Tab reaching the host moves focus out of the field, which is the bug Fix rapid Tab leaking into the host after a final-word accept #484 fixed. Delivering it late would be worse.shownHead/acceptanceChunk, aGhostTextLayoutcontract test (a truncated head is a strict prefix of the unconsumed text, including after an advance), interaction-state tests for full, phrase and unshown preparation, and coordinator tests for capped full accept, the held-present unshown press, and a swallowed Tab that does not accept the continuation that follows it. The rig overlay gains a settabletruncatedDisplayText.Validation
Not built or run locally (no disk space on the authoring machine); CI build and tests are the compile check.
No files were added or removed and
project.ymlis unchanged.xcodegen generateproduces no diff.Rebuilt from scratch on
mainatc14b1700, after the #928–#955 refactors, instead of rebased: 15 of 18 files had moved. The behavior decisions are unchanged. The adaptations:truncatedDisplayTextreads the presentation lifecycle from Make the overlay's presentation lifecycle and the font and caret measurement states explicit #941.PostExhaustionAcceptanceStatekeeps its new singleWindowenum, with the case renamedarmedWithHeldPress.The first CI run failed one existing test,
SuggestionCoordinatorWordCompletionTests.testAcceptedCorrectionWaitsForPublishedTextAndQueuesNextTab. It asserted that a Tab pressed while an accepted typo correction is still publishing inserts the next word ("the"). At that press there is no session, the correction accept has hidden the overlay, and "the package" exists only as a prefetched continuation. The test asserts the missing session itself. That text is first presented insideapplywhen the publish lands, and the old flush accepted it in that same turn, which is exactly the case this PR removes. The post-exhaustion window only arms with no session and a hidden overlay, so no held press can ever refer to text already on screen. I renamed the test to…AndSwallowsTheRapidTaband kept its lookahead and request assertions. After the publish it now asserts that nothing was inserted, the continuation was shown, and the window closed. A fresh press then inserts "the" and leaves " package", the same end state the old assertions checked.Linked issues
None filed. Addresses M10 ("truncated ghost, full insert" and "queued Tab") from a static security review of
8cdbea2.Risk / rollout notes
This changes the core accept flow. What users will notice:
GhostTextLayout.maximumRowsalready fall back to the card. Worth a follow-up.OverlayController's inline session and published state staying in step. I traced every place they change (present, advance, calibration re-layout, font-registration redraw, card fallback, hide), but CI and a manual check in a single-line web field and an Obsidian note with text below the caret are the real verification.PostExhaustionAcceptanceStatemembers are renamed (hasQueuedAccept→hasHeldPress,queueAcceptIfArmed→holdPressIfArmed,consumeQueuedAccept→consumeHeldPress, window casearmedWithQueuedAccept→armedWithHeldPress) so the names match the new semantics.🤖 Generated with Claude Code