Skip to content

Problem that happens when deleting characters in insert mode. #2

Closed

Description

@frapank

Pressing backspace in insert mode can crash the program at src/editor/editing.rs:46: cannot remove a char from the end of a string

To reproduce it:

  1. Go to an empty line.
  2. Press a and type aaa.
  3. Press backspace.

The causes are:

  1. insert_forward (a) increments row without checking the line length, so the cursor ends up past the end of the line.
  2. remove_char then can't find the character and calls line.remove(len), which panics.
  3. move_tonext (w) has the same problem. It also mixes characters and bytes (line.len()).

To fix it:

  1. Clamp the cursor in insert_forward with (buffer.row + 1).min(len).
  2. In remove_char, return early when the character isn't found.
  3. In move_tonext, use chars().count() instead of len().

Activity

  1. self-assigned this
    on Oct 24, 2026
  2. added a commit that references this issue on Oct 25, 2026
    4202d55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions