aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-08-29 13:59:29 +0000
committerBlaž Hrastnik2021-08-29 13:59:29 +0000
commit51328a49662b7daf0fda83e30268fff252d7d00e (patch)
treee6ddf689b9a15e304fe4d2a58ae3c258ac965e9b
parentd6ccc150c78adf72f77f26185ea7a559983ed2d0 (diff)
dap: extract dap_pos_to_pos
-rw-r--r--helix-term/src/application.rs44
1 files changed, 28 insertions, 16 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index 9aa98271..b92512be 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -331,24 +331,36 @@ impl Application {
let (view, doc) = current!(self.editor);
+ fn dap_pos_to_pos(
+ doc: &helix_core::Rope,
+ line: usize,
+ column: usize,
+ ) -> Option<usize> {
+ // 1-indexing to 0 indexing
+ let line = doc.try_line_to_char(line - 1).ok()?;
+ let pos = line + column;
+ // TODO: this is probably utf-16 offsets
+ Some(pos)
+ }
+
let text_end = doc.text().len_chars().saturating_sub(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().try_line_to_char(end_line - 1).unwrap_or(0)
- + end_column.unwrap_or(0);
- doc.set_selection(
- view.id,
- Selection::new(
- helix_core::SmallVec::from_vec(vec![Range::new(
- start.min(text_end),
- end.min(text_end),
- )]),
- 0,
- ),
- );
+ let start = dap_pos_to_pos(doc.text(), line, column).unwrap_or(0);
+
+ let selection = if let Some(end_line) = end_line {
+ let end = dap_pos_to_pos(doc.text(), end_line, end_column.unwrap_or(0))
+ .unwrap_or(0);
+
+ Selection::new(
+ helix_core::SmallVec::from_vec(vec![Range::new(
+ start.min(text_end),
+ end.min(text_end),
+ )]),
+ 0,
+ )
} else {
- doc.set_selection(view.id, Selection::point(start.min(text_end)));
- }
+ Selection::point(start.min(text_end))
+ };
+ doc.set_selection(view.id, selection);
align_view(doc, view, Align::Center);
}
self.editor.set_status(status);