Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
jeremy wants to merge1 commit intomain
base:main
Choose a base branch
Loading
fromsafari-smart-quotes-cursor-fix

Conversation

@jeremy
Copy link
Member

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.

/cc@rosa

@jeremyjeremyforce-pushed thesafari-smart-quotes-cursor-fix branch from7596228 to5a239e1CompareOctober 4, 2025 19:34
@jeremyjeremy requested a review fromCopilotOctober 4, 2025 21:43
Copy link

CopilotAI left a 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.

FileDescription
src/trix/models/selection_manager.jsAdds check to prevent selection sync during Safari smart quotes workaround
src/trix/controllers/level_2_input_controller.jsImplements the main workaround logic with cursor positioning calculations and event handling
src/test/system/level_2_input_test.jsAdds three test cases covering smart quotes and autocorrect behavior

Tip: Customize your code reviews with copilot-instructions.md.Create the file orlearn how to get started.

@jeremyjeremyforce-pushed thesafari-smart-quotes-cursor-fix branch from5a239e1 to3205c34CompareOctober 4, 2025 22:38
@jeremyjeremy requested a review fromCopilotOctober 4, 2025 22:38
Copy link

CopilotAI left a 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 orlearn how to get started.

Safari 26 positions the cursor incorrectly after smart quotes textsubstitution, causing it to jump back 1-2 characters.After insertReplacementText events, the cursor is incorrectlypositioned. Trix's selectionDidChange handler syncs, corrupting itsinternal 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 inSafari, hit Enter twice then "I'll " - including the final space. Thecursor should remain after the final space, no after the replacedapostrophe. Similarly with autocorrect: the cursor should not move tothe end of the spelling-corrected word.
@jeremyjeremyforce-pushed thesafari-smart-quotes-cursor-fix branch from3205c34 to32165b8CompareOctober 5, 2025 00:24
@jeremyjeremy requested a review fromCopilotOctober 5, 2025 00:25
Copy link

CopilotAI left a 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 orlearn how to get started.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

Copilot code reviewCopilotCopilot left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@jeremy

[8]ページ先頭

©2009-2025 Movatter.jp