Skip to content

Panic when incrementing two -1 values #2019

Closed
@joegm

Description

@joegm

Summary

The original summary included a lot of context that isn't related. After some discussion this is what has been found.

If you have a file with the following:

-1
-1

And you enter the following keystrokes:
% s - <enter> C-a

Helix panics.

This doesn't happen when there is a character, space or empty line after the two lines:

-1
-1

(Helix doesn't panic with the above input on this text)

Here is the backtrace with RUST_BACKTRACE=1:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Char index out of bounds: char index 4, Rope/RopeSlice char length 3', /home/jm/.cargo/registry/src/g.yxqyang.asia-1ecc6299db9ec823/ropey-1.4.1/src/slice.rs:349:41
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14
   2: core::result::unwrap_failed
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/result.rs:1690:5
   3: ropey::slice::RopeSlice::char_to_byte
   4: helix_core::graphemes::nth_next_grapheme_boundary
   5: helix_core::selection::Range::grapheme_aligned
   6: helix_core::selection::Selection::ensure_invariants
   7: helix_view::document::Document::apply_impl
   8: helix_view::document::Document::apply
   9: helix_term::commands::increment_impl
  10: helix_term::ui::editor::EditorView::handle_keymap_event
  11: <helix_term::ui::editor::EditorView as helix_term::compositor::Component>::handle_event
  12: helix_term::compositor::Compositor::handle_event
  13: helix_term::application::Application::handle_terminal_events
  14: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
  15: tokio::park::thread::CachedParkThread::block_on
  16: tokio::runtime::thread_pool::ThreadPool::block_on
  17: tokio::runtime::Runtime::block_on
  18: hx::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

I also now updated the Helix version to my now current version on this issue because this bug still exists at the time of writing.

Helix log

~/.cache/helix/helix.log
please provide a copy of `~/.cache/helix/helix.log` here if possible, you may need to redact some of the lines


[helix.log](https://github.com/helix-editor/helix/files/8451943/helix.log)

Platform

Linux

Terminal Emulator

alacritty

Helix Version

22.03-105-gcc68fa85

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-helix-termArea: Helix term improvementsC-bugCategory: This is a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions