Skip to content

editor: Fix Accessibility Keyboard word completion corrupting text#50676

Merged
Veykril merged 2 commits intozed-industries:mainfrom
criticic:fix-accessibility-keyboard-word-completion
Mar 19, 2026
Merged

editor: Fix Accessibility Keyboard word completion corrupting text#50676
Veykril merged 2 commits intozed-industries:mainfrom
criticic:fix-accessibility-keyboard-word-completion

Conversation

@criticic
Copy link
Copy Markdown
Contributor

@criticic criticic commented Mar 4, 2026

When typing with the macOS Accessibility Keyboard and clicking a word completion suggestion, text was corrupted in several ways.

macOS sends insertText:replacementRange: when a completion is selected. The replacement range was passed to selection_replacement_ranges using the wrong offset type, causing incorrect delta calculation for multi-cursor scenarios. Additionally, backspace was called unconditionally even when the replacement range was empty (as with the trailing space the Accessibility Keyboard appends), deleting the last character of every completed word. Finally, an empty replacement range in a multi-cursor context carries a stale cursor position from macOS's single-cursor view of the buffer, so it is now ignored and text is inserted at each cursor's actual position instead.

Closes #38052

Release Notes:

  • Fixed text corruption when using macOS Accessibility Keyboard word completion.

Copilot AI review requested due to automatic review settings March 4, 2026 07:10
@cla-bot
Copy link
Copy Markdown

cla-bot bot commented Mar 4, 2026

We require contributors to sign our Contributor License Agreement, and we don't have @criticic on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@zed-community-bot zed-community-bot bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Mar 4, 2026
@criticic criticic force-pushed the fix-accessibility-keyboard-word-completion branch from 29af3fc to 380b05d Compare March 4, 2026 07:11
@cla-bot
Copy link
Copy Markdown

cla-bot bot commented Mar 4, 2026

We require contributors to sign our Contributor License Agreement, and we don't have @criticic on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@criticic
Copy link
Copy Markdown
Contributor Author

criticic commented Mar 4, 2026

@cla-bot check

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Mar 4, 2026
@cla-bot
Copy link
Copy Markdown

cla-bot bot commented Mar 4, 2026

The cla-bot has been summoned, and re-checked this pull request!

Copy link
Copy Markdown
Contributor

Copilot AI 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

Fixes macOS Accessibility Keyboard word-completion interactions in the editor by correctly interpreting insertText:replacementRange: and avoiding unintended deletions/cursor misplacement, especially with multi-cursor selections.

Changes:

  • Treats IME composition replacement ranges as operating on marked ranges (per-cursor), rather than using the reported replacement range.
  • Ignores empty replacement ranges (interpreting them as “insert at cursor”), preventing stale single-cursor offsets from corrupting multi-cursor inserts.
  • Avoids calling backspace when all replacement ranges are empty, preventing deletion of the preceding character (e.g., trailing-space completions).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@criticic criticic force-pushed the fix-accessibility-keyboard-word-completion branch from 380b05d to 0fb68dd Compare March 4, 2026 07:17
When macOS sends insertText:replacementRange: (e.g. from the Accessibility
Keyboard word completion panel), two bugs caused text corruption:

1. During IME composition with multiple cursors, the replacement range
   reported by macOS is relative to the first marked region (the only one
   visible via marked_text_range). Using selection_replacement_ranges with
   this absolute offset caused a wildly wrong delta for cursors at different
   positions, corrupting or missing replacements for all but one cursor.

   Fix by using the marked ranges themselves as the replacement targets when
   active composition ranges exist, since they already cover every cursor.

2. After setting the selection, backspace was called unconditionally. When
   the Accessibility Keyboard inserts a trailing space it sends an empty
   replacement range (cursor..cursor), and calling backspace on an empty
   selection moves the cursor left and deletes the preceding character —
   stripping the last character of every completed word.

   Fix by skipping the backspace call when all replacement ranges are empty.
@criticic criticic force-pushed the fix-accessibility-keyboard-word-completion branch from 0fb68dd to 0582071 Compare March 4, 2026 07:41
@criticic criticic requested a review from Copilot March 4, 2026 07:44
Copy link
Copy Markdown
Contributor

Copilot AI 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 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@zelenenka zelenenka added the guild Pull requests by someone in Zed Guild. NOTE: the label application is automated via github actions label Mar 16, 2026
Copy link
Copy Markdown
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Veykril Veykril enabled auto-merge (squash) March 19, 2026 08:08
@Veykril Veykril merged commit ed42b80 into zed-industries:main Mar 19, 2026
29 of 31 checks passed
AmaanBilwar pushed a commit to AmaanBilwar/zed that referenced this pull request Mar 20, 2026
…ed-industries#50676)

When typing with the macOS Accessibility Keyboard and clicking a word
completion suggestion, text was corrupted in several ways.

macOS sends `insertText:replacementRange:` when a completion is
selected. The replacement range was passed to
`selection_replacement_ranges` using the wrong offset type, causing
incorrect delta calculation for multi-cursor scenarios. Additionally,
`backspace` was called unconditionally even when the replacement range
was empty (as with the trailing space the Accessibility Keyboard
appends), deleting the last character of every completed word. Finally,
an empty replacement range in a multi-cursor context carries a stale
cursor position from macOS's single-cursor view of the buffer, so it is
now ignored and text is inserted at each cursor's actual position
instead.

Closes zed-industries#38052

Release Notes:

- Fixed text corruption when using macOS Accessibility Keyboard word
completion.
toshmukhamedov pushed a commit to toshmukhamedov/zed that referenced this pull request Mar 20, 2026
…ed-industries#50676)

When typing with the macOS Accessibility Keyboard and clicking a word
completion suggestion, text was corrupted in several ways.

macOS sends `insertText:replacementRange:` when a completion is
selected. The replacement range was passed to
`selection_replacement_ranges` using the wrong offset type, causing
incorrect delta calculation for multi-cursor scenarios. Additionally,
`backspace` was called unconditionally even when the replacement range
was empty (as with the trailing space the Accessibility Keyboard
appends), deleting the last character of every completed word. Finally,
an empty replacement range in a multi-cursor context carries a stale
cursor position from macOS's single-cursor view of the buffer, so it is
now ignored and text is inserted at each cursor's actual position
instead.

Closes zed-industries#38052

Release Notes:

- Fixed text corruption when using macOS Accessibility Keyboard word
completion.
AmaanBilwar pushed a commit to AmaanBilwar/zed that referenced this pull request Mar 23, 2026
…ed-industries#50676)

When typing with the macOS Accessibility Keyboard and clicking a word
completion suggestion, text was corrupted in several ways.

macOS sends `insertText:replacementRange:` when a completion is
selected. The replacement range was passed to
`selection_replacement_ranges` using the wrong offset type, causing
incorrect delta calculation for multi-cursor scenarios. Additionally,
`backspace` was called unconditionally even when the replacement range
was empty (as with the trailing space the Accessibility Keyboard
appends), deleting the last character of every completed word. Finally,
an empty replacement range in a multi-cursor context carries a stale
cursor position from macOS's single-cursor view of the buffer, so it is
now ignored and text is inserted at each cursor's actual position
instead.

Closes zed-industries#38052

Release Notes:

- Fixed text corruption when using macOS Accessibility Keyboard word
completion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions guild Pull requests by someone in Zed Guild. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Accessibility: macOS On-screen keyboard word completion issues

6 participants