feat(settings): add opt-in trailing space after accepting a suggestion#675
Merged
Conversation
When the user enables "Add Space After Accepting", an accept that finishes a word and exhausts the suggestion also types a trailing space so they can keep typing without reaching for the space bar. The space is gated on exhaustion (only the final chunk; a mid-suggestion accept already gets the next chunk's own leading space) and suppressed after punctuation, whitespace, or a space-less script. Defaults off so the WYSIWYG accept behavior is unchanged unless opted into.
Comment on lines
+77
to
+78
| description: "When accepting a suggestion finishes a word, also add a space so you can " + | ||
| "keep typing. Skipped when it already ends in punctuation or a space.", |
Contributor
There was a problem hiding this comment.
The description mentions punctuation and space as suppression cases but omits spaceless scripts (CJK, Thai, etc.). A user who writes in Japanese and enables this toggle will notice no space ever appears — the description as written doesn't tell them why. A small addition like "or in a language that doesn't use spaces (e.g. Chinese, Japanese)" would set the right expectation.
Suggested change
| description: "When accepting a suggestion finishes a word, also add a space so you can " + | |
| "keep typing. Skipped when it already ends in punctuation or a space.", | |
| description: "When accepting a suggestion finishes a word, also add a space so you can " + | |
| "keep typing. Skipped when it already ends in punctuation, a space, or a language " + | |
| "that doesn't use spaces (e.g. Chinese, Japanese).", |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
# Conflicts: # Cotabby/App/Coordinators/SuggestionCoordinator+Acceptance.swift
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
Adds a new opt-in "Add Space After Accepting" toggle (Settings → General → Behavior). When on, accepting a suggestion that finishes a word also types a trailing space so the user can keep typing without reaching for the space bar. This was a requested feature; it's off by default so existing WYSIWYG accept behavior is unchanged unless opted into.
The space is only appended when the accept exhausts the suggestion (the final chunk) — a mid-suggestion word accept is already followed by the next chunk's own leading space, so a space there would double up. Exhaustion is predicted the same way
commitAcceptedChunkdecides it (session.advancing(by:).isExhausted). The space is suppressed when the inserted text ends in punctuation (done.,(yes),really?!), whitespace, or a space-less script (CJK/Thai never separate words with spaces), reusing the existingisAcceptanceWordCharacter/beginsSpacelessScriptWordprimitives. Session accounting still advances by the unchangedacceptedChunk, and the session tears down on exhaustion, so the extra space never disturbs consumed-suffix reconciliation.Validation
Pure rule lives in
SuggestionSessionReconciler.insertionChunkAppendingTrailingSpace(_:)(Support/), covered by new unit tests for word/digit/punctuation/whitespace/CJK/empty cases. The coordinator gates it via a smallinsertionTextApplyingAutoSpace(...)helper (kept separate soacceptSuggestionstays under the cyclomatic-complexity limit).Linked issues
Risk / rollout notes
cotabbyAddSpaceAfterAccept, defaults to false, so no behavior change for existing installs until opted in. Threaded through the full settings stack (data → store load/write-back/save → model@Published/setter/snapshot/Combine publisher → snapshot struct → UI toggle → search index).CombineLatestcap.Greptile Summary
This PR adds an opt-in "Add Space After Accepting" toggle in Settings → General → Behavior. When enabled, accepting the final chunk of a suggestion appends a trailing space, letting users continue typing without pressing Space. The setting defaults to
falseso no behavior change occurs for existing installs.SuggestionSessionReconciler.insertionChunkAppendingTrailingSpace, which skips the space for text ending in punctuation, whitespace, or a spaceless-script (CJK/Thai) glyph; 6 new unit tests cover every branch.session.advancing(by: acceptedChunk.count).isExhaustedbeforecommitAcceptedChunk, matching the same logic, so a mid-suggestion accept (where the next chunk already carries a leading space) never receives a doubled space. Session accounting still advances by the unmodifiedacceptedChunk, keeping consumed-suffix reconciliation intact.Confidence Score: 5/5
Safe to merge — the feature is off by default, exhaustion prediction uses the same advancing logic as the actual commit, and suppression guards (punctuation, whitespace, CJK) are fully unit-tested.
The acceptance coordinator carefully predicts exhaustion before inserting so the space is never appended to a mid-suggestion chunk, and session accounting still advances by the unmodified acceptedChunk, keeping consumed-suffix reconciliation intact. The new setting is opt-in with a false default, so existing installs see no change. The pure helper function is isolated in SuggestionSessionReconciler with comprehensive unit tests, and the Combine publisher nesting to stay within the four-input cap follows the established codebase pattern.
No files require special attention.
Important Files Changed
Sequence Diagram
sequenceDiagram participant U as User (Tab key) participant SC as SuggestionCoordinator participant R as SuggestionSessionReconciler participant SI as SuggestionInserter participant S as ActiveSuggestionSession U->>SC: acceptSuggestion() SC->>R: insertionChunk(forAcceptedChunk:precedingText:) R-->>SC: insertionChunk (leading-space stripped if needed) SC->>S: advancing(by: acceptedChunk.count).isExhausted S-->>SC: isExhausted (exhaustion prediction) alt addSpaceAfterAccept ON AND session exhausted SC->>R: insertionChunkAppendingTrailingSpace(insertionChunk) R-->>SC: insertionText (+ trailing space if word char, non-CJK) else setting OFF or not exhausted SC-->>SC: "insertionText = insertionChunk" end SC->>SI: insert(insertionText) SI-->>SC: success / failure SC->>S: commitAcceptedChunk(acceptedChunk) alt exhausted S-->>SC: .exhausted SC->>SC: hideOverlay, armPostExhaustionAcceptance, schedulePrediction else advanced S-->>SC: .advanced(session) SC->>SC: presentAdvancedOverlay(insertionChunk) endReviews (2): Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." | Re-trigger Greptile