summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Sharshakov2021-08-23 18:25:58 +0000
committerDmitry Sharshakov2021-08-23 18:25:58 +0000
commitec599a1eac0fca7d7499f1acb7f306acbaee8cca (patch)
tree26103a10210b0f4ba229903fa2e3ac59a9ebedbc
parent3a5e044c8958d6407516c194eeeb3b8961c00632 (diff)
Do not panic if entered unknown code via stack trace
e.g. Rust std library
-rw-r--r--helix-term/src/application.rs16
1 files 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);
}