Skip to content

desktop2: word-delete with an active selection crashes on next Backspace #728

Closed

Description

@wtchronos

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).

  1. Launch jcode-desktop2 on macOS.
  2. Type hello world.
  3. Press Shift+Left once to select the final character.
  4. Press Option+Backspace.
  5. 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

  1. 1jehuang commented on Aug 2, 2026

    @1jehuang
    Owner

    Confirmed and fixed. Your diagnosis and suggested fix were both exactly right.

    delete_back/delete_forward consume a selection first; delete_word_back/delete_word_forward did not. So a word-delete drained the buffer while anchor kept 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-C key_down boundary, 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

  2. added a commit that references this issue on Aug 2, 2026
    621a264
  3. added
    bug
    priority: high
    triage: reproducible
    autonomous: clear
    triage: fixed-pending-release
    on Aug 2, 2026
  4. added 2 commits that reference this issue on Aug 2, 2026
  5. added a commit that references this issue on Aug 5, 2026
    459b70f
  6. added 4 commits that reference this issue on Aug 30, 2026
    47dcbab
    56f9d8a
    48df8a4
    a10fbff
  7. 3 remaining items

  8. added 3 commits that reference this issue on Sep 18, 2026
    9f2bd5f
    fbc0ba7
    d16ea0a
  9. added 3 commits that reference this issue on Oct 9, 2026
    5767a23
    7379562
    be8fbf0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    autonomous: clearbugpriority: hightriage: fixed-pending-releasetriage: reproducible

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions