fix: enable composer autocorrect except on / @ # tokens - #1690
fix: enable composer autocorrect except on / @ # tokens#1690Chessing234 wants to merge 1 commit into
Conversation
The composer kept autocorrect off for every keystroke so commands, mentions, and geohashes would not be rewritten. Prose was paying that cost. Disable it only while the token under the cursor starts with /, @, or # (permissionlesstech#969).
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fe48c819b7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ComposerAutocorrectPolicy.shouldDisable( | ||
| for: messageText, | ||
| cursor: messageText.count | ||
| ) |
There was a problem hiding this comment.
Use the text field's real cursor location
When a user moves the caret back into a token that is not at the end of the message—for example, editing Please notify @al tomorrow at @al—this always supplies the end-of-message position. The policy therefore examines tomorrow, enables autocorrection, and can rewrite the mention or geohash that this change is meant to preserve. Track the text field selection/insertion point (or apply a conservative fallback) instead of using messageText.count.
Useful? React with 👍 / 👎.
| if let lastWhitespace = before.lastIndex(where: { $0.isWhitespace }) { | ||
| return String(before[before.index(after: lastWhitespace)...]) |
There was a problem hiding this comment.
Recognize punctuation-adjacent mention and geohash tokens
When a valid token follows punctuation instead of whitespace, such as hello,@al or (#u4pr, this returns the entire whitespace-delimited run and its first character is not @ or #, so autocorrection is enabled. The existing mention and hashtag regexes recognize these substrings without requiring preceding whitespace, meaning this newly enables corrections for supported autocomplete/formatting tokens; locate the marker within the run or use the same token-boundary rules as those parsers.
Useful? React with 👍 / 👎.
Summary
.autocorrectionDisabled(true)for every keystroke so/commands,@mentions, and#geohashtokens would not be rewritten. Prose was paying that cost (Enable auto correction when typing a message #969)./,@, or#.Test plan
swiftctypecheck ofComposerAutocorrectPolicy.swiftunder Swift 5 and 6/,@,#, completed/msgargument, token at cursor)xcodebuildtest suite — this machine has Command Line Tools only, no Xcode; CI coversComposerAutocorrectPolicyTestsand the composer wiring/msg,@al, and#u4prshould notMade with Cursor