Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic when reloading a file that has shrunk #2305

Closed
paholg opened this issue Apr 27, 2022 · 3 comments · Fixed by #2506
Closed

Panic when reloading a file that has shrunk #2305

paholg opened this issue Apr 27, 2022 · 3 comments · Fixed by #2506
Labels
A-helix-term Area: Helix term improvements C-bug Category: This is a bug

Comments

@paholg
Copy link

paholg commented Apr 27, 2022

Summary

If you reload a file while your cursor is out-of-bounds of the reloaded file, a panic occurs.

Backtrace:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Line index out of bounds: line index 4569, Rope/RopeSlice line count 2923', /build/helix-22.03-vendor.tar.gz/ropey/src/slice.rs:424:41
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::result::unwrap_failed
   3: ropey::slice::RopeSlice::line_to_byte
   4: helix_term::ui::editor::EditorView::doc_syntax_highlights
   5: helix_term::ui::editor::EditorView::render_view
   6: <helix_term::ui::editor::EditorView as helix_term::compositor::Component>::render
   7: helix_term::compositor::Compositor::render
   8: helix_term::application::Application::handle_terminal_events
   9: helix_term::application::Application::event_loop::{{closure}}
  10: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
  11: tokio::park::thread::CachedParkThread::block_on
  12: tokio::runtime::thread_pool::ThreadPool::block_on
  13: tokio::runtime::Runtime::block_on
  14: hx::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Reproduction Steps

  1. Open a file and go to line N (N must be at least some number. It works for me at ~200).
  2. Externally edit the file so that it is much shorter than N
  3. :reload the file.

Helix log

There is no relevant log information.

Platform

Linux

Terminal Emulator

gnome-terminal

Helix Version

helix 22.03 (d4e45fd)

@paholg paholg added the C-bug Category: This is a bug label Apr 27, 2022
@the-mikedavis the-mikedavis added the A-helix-term Area: Helix term improvements label Apr 27, 2022
@pppKin
Copy link
Contributor

pppKin commented May 6, 2022

Can reproduce. ensure_cursor_in_view after a reload seems necessary.

Something like this would solve the issue.

doc.reload(view.id).and_then(|_| {
    view.ensure_cursor_in_view(doc, 0);
    Ok(())
})

What this look like, in case anyone is just wondering and don't want to cargo run, is to bring the end of the file to top of the editor view.
I think for better user experience we might want to scroll back a bit further. What do you guys think?

@Johan-Mi
Copy link

Issue still reproduces with :reflow, for example when reflowing the entire contents of a file consisting of ~40 single-character lines.

@archseer
Copy link
Member

Yeah, reflow is a separate command that needs a similar fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements C-bug Category: This is a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants