-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Safari: fix incorrect cursor position after smart quote insertion #1261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
7596228
to
5a239e1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a Safari 26 bug where the cursor position is incorrect after smart quote text substitution. The cursor incorrectly jumps back 1-2 characters instead of remaining at the expected position after the replacement.
- Implements a workaround to detect "at cursor" vs "before cursor" text replacements using distance heuristics
- Manually calculates and sets correct cursor positioning for smart quotes while preventing Safari's buggy sync
- Adds comprehensive test coverage for smart quotes and autocorrect scenarios
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
src/trix/models/selection_manager.js | Adds check to prevent selection sync during Safari smart quotes workaround |
src/trix/controllers/level_2_input_controller.js | Implements the main workaround logic with cursor positioning calculations and event handling |
src/test/system/level_2_input_test.js | Adds three test cases covering smart quotes and autocorrect behavior |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
5a239e1
to
3205c34
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Safari 26 positions the cursor incorrectly after smart quotes text substitution, causing it to jump back 1-2 characters. After insertReplacementText events, the cursor is incorrectly positioned. Trix's selectionDidChange handler syncs, corrupting its internal state. Hack to work around it: * Detect whether replacement is "at cursor" (smart quotes) vs "before cursor" (autocorrect) with <= 2 char distance heuristic. * For at-cursor replacements: manually calculate correct positioning accounting for length diff and triggering character (+1); set cursor in Trix; skip 3 input events to prevent corrupt sync; prevent selectionDidChange from syncing in the meantime; restore cursor position in requestAnimationFrame (no visible cursor movement). To reproduce the issue: enable Edit > Substitutions > Smart Quotes in Safari, hit Enter twice then "I'll " - including the final space. The cursor should remain after the final space, no after the replaced apostrophe. Similarly with autocorrect: the cursor should not move to the end of the spelling-corrected word.
3205c34
to
32165b8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 3 out of 4 changed files in this pull request and generated no new comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Safari 26 positions the cursor incorrectly after smart quotes text substitution, causing it to jump back 1-2 characters.
After insertReplacementText events, the cursor is incorrectly positioned. Trix's selectionDidChange handler syncs, corrupting its internal state.
Hack to work around it:
To reproduce the issue: enable Edit > Substitutions > Smart Quotes in Safari, hit Enter twice then "I'll " - including the final space. The cursor should remain after the final space, no after the replaced apostrophe. Similarly with autocorrect: the cursor should not move to the end of the spelling-corrected word.
/cc @rosa