From ec599a1eac0fca7d7499f1acb7f306acbaee8cca Mon Sep 17 00:00:00 2001 From: Dmitry Sharshakov Date: Mon, 23 Aug 2021 21:25:58 +0300 Subject: [PATCH] Do not panic if entered unknown code via stack trace e.g. Rust std library --- helix-term/src/application.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 82bba076..f9789d79 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -324,17 +324,21 @@ impl Application { .unwrap(); let (view, doc) = current!(self.editor); - log::info!("{:?}", doc); - let start = doc.text().line_to_char(line - 1) + column; + + let text_end = doc.text().len_chars() - 1; + let start = doc.text().try_line_to_char(line - 1).unwrap_or(0) + column; if let Some(end_line) = end_line { - let end = - doc.text().line_to_char(end_line - 1) + end_column.unwrap_or(0); + let end = doc.text().try_line_to_char(end_line - 1).unwrap_or(0) + + end_column.unwrap_or(0); doc.set_selection( view.id, - Selection::new(smallvec![Range::new(start, end)], 0), + Selection::new( + smallvec![Range::new(start.min(text_end), end.min(text_end))], + 0, + ), ); } else { - doc.set_selection(view.id, Selection::point(start)); + doc.set_selection(view.id, Selection::point(start.min(text_end))); } align_view(doc, view, Align::Center); }