Commit 32165b8
committed
Safari: fix incorrect cursor position after smart quote insertion
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.1 parent b307451 commit 32165b8
File tree
4 files changed
+2089
-1827
lines changed- action_text-trix/app/assets/javascripts
- src
- test/system
- trix
- controllers
- models
4 files changed
+2089
-1827
lines changed
0 commit comments