Repository navigation
Description
Summary
On macOS, a word-delete while the composer has an active selection can leave the selection anchor past the shortened buffer. The next ordinary Backspace panics in Editor::delete_selection, then aborts because the panic crosses winit's Objective-C key_down boundary.
Reproduction
Tested with jcode-desktop2 built from the current master lineage (desktop2 sources at 8f614c600; local HEAD had only an unrelated context-compaction commit on top).
- Launch
jcode-desktop2on macOS. - Type
hello world. - Press Shift+Left once to select the final character.
- Press Option+Backspace.
- Press ordinary Backspace.
This reproduces deterministically.
Actual behavior
The process aborts:
thread 'main' panicked at crates/jcode-desktop2/src/editor.rs:100:40:
byte index 11 is out of bounds of `hello d`
...
panic in a function that cannot unwind
...
winit::platform_impl::macos::view::WinitView::key_down
The original user-triggered crash had the same first panic with a different buffer:
byte index 14 is out of bounds of `des this work`
Expected behavior
Word-delete should replace the active selection, matching ordinary Backspace/Delete and normal text-field behavior. A later Backspace must not see stale selection offsets.
Cause
delete_back and delete_forward first call delete_selection(), but delete_word_back and delete_word_forward do not. A word-delete can therefore drain the buffer while retaining the old anchor byte offset.
Verified minimal fix
Add the same early selection handling to both word-delete methods:
if self.delete_selection().is_some() {
return;
}A focused regression test covering backward and forward word-delete with active selections fails before the change and passes after it. The exact GUI sequence above changes from process abort to APP_ALIVE with zero panic lines.
Focused validation:
test editor::selection_tests::word_delete_replaces_the_selection_without_stale_offsets ... ok
Note: the full desktop2 suite currently has an unrelated baseline failure in mem::tests::the_sampler_throttles_between_refreshes; it fails identically without this editor change.
Activity
1jehuang commentedon Aug 2, 2026
Confirmed and fixed. Your diagnosis and suggested fix were both exactly right.
delete_back/delete_forwardconsume a selection first;delete_word_back/delete_word_forwarddid not. So a word-delete drained the buffer whileanchorkept pointing past the new end, and the next Backspace sliced out of bounds. The abort rather than a clean unwind is because the panic crosses winit's Objective-Ckey_downboundary, as you noted.Applied the minimal fix you specified to both word-delete methods.
Two regression tests added, one for backward and one for forward word-delete with an active selection. I verified they earn their keep: both fail on the pre-fix code (the backward one reproduces your exact sequence,
hello world/ Shift+Left / Option+Backspace / Backspace) and pass after. Full editor suite is green at 62 tests.Thanks for the deterministic repro and for tracing it to the asymmetry between the two code paths, that made this a quick fix.
Commit:
621a264b0, shipping in #727.--- — Jcode agent (automated triage), on behalf of @1jehuang
fix(desktop2): word-delete replaces an active selection (fixes #728)
test(desktop2): split the #728 editor regressions into their own module
test(desktop2): sweep every mutator for stale selections (refs #728)
chore: sync fork with upstream (224 behind), preserve fork commits (#2)
fix(desktop2): word-delete replaces an active selection (fixes 1jehua…
test(desktop2): split the 1jehuang#728 editor regressions into their …
test(desktop2): sweep every mutator for stale selections (refs 1jehua…
fix(desktop2): word-delete replaces an active selection (fixes 1jehua…
3 remaining items
test(desktop2): split the 1jehuang#728 editor regressions into their …
test(desktop2): sweep every mutator for stale selections (refs 1jehua…
fix(desktop2): word-delete replaces an active selection (fixes 1jehua…
test(desktop2): split the 1jehuang#728 editor regressions into their …
test(desktop2): sweep every mutator for stale selections (refs 1jehua…
fix(desktop2): word-delete replaces an active selection (fixes 1jehua…
test(desktop2): split the 1jehuang#728 editor regressions into their …
test(desktop2): sweep every mutator for stale selections (refs 1jehua…
fix(desktop2): word-delete replaces an active selection (fixes 1jehua…
test(desktop2): split the 1jehuang#728 editor regressions into their …
test(desktop2): sweep every mutator for stale selections (refs 1jehua…
Triage batch: fixes for 1jehuang#712, 1jehuang#715, 1jehuang#719, 1je…
fix(desktop2): word-delete replaces an active selection (fixes 1jehua…
test(desktop2): split the 1jehuang#728 editor regressions into their …
test(desktop2): sweep every mutator for stale selections (refs 1jehua…