editor: Fix Accessibility Keyboard word completion corrupting text#50676
Conversation
|
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'. |
29af3fc to
380b05d
Compare
|
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'. |
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
There was a problem hiding this comment.
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
backspacewhen 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.
380b05d to
0fb68dd
Compare
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.
0fb68dd to
0582071
Compare
There was a problem hiding this comment.
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.
…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.
…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.
…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.
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 toselection_replacement_rangesusing the wrong offset type, causing incorrect delta calculation for multi-cursor scenarios. Additionally,backspacewas 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: