dap: extract dap_pos_to_pos

This commit is contained in:
Blaž Hrastnik 2021-08-29 22:59:29 +09:00
parent d6ccc150c7
commit 51328a4966

View file

@ -331,24 +331,36 @@ impl Application {
let (view, doc) = current!(self.editor); let (view, doc) = current!(self.editor);
let text_end = doc.text().len_chars().saturating_sub(1); fn dap_pos_to_pos(
let start = doc.text().try_line_to_char(line - 1).unwrap_or(0) + column; doc: &helix_core::Rope,
if let Some(end_line) = end_line { line: usize,
let end = doc.text().try_line_to_char(end_line - 1).unwrap_or(0) column: usize,
+ end_column.unwrap_or(0); ) -> Option<usize> {
doc.set_selection( // 1-indexing to 0 indexing
view.id, let line = doc.try_line_to_char(line - 1).ok()?;
Selection::new( let pos = line + column;
helix_core::SmallVec::from_vec(vec![Range::new( // TODO: this is probably utf-16 offsets
start.min(text_end), Some(pos)
end.min(text_end),
)]),
0,
),
);
} else {
doc.set_selection(view.id, Selection::point(start.min(text_end)));
} }
let text_end = doc.text().len_chars().saturating_sub(1);
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 {
Selection::point(start.min(text_end))
};
doc.set_selection(view.id, selection);
align_view(doc, view, Align::Center); align_view(doc, view, Align::Center);
} }
self.editor.set_status(status); self.editor.set_status(status);