diff options
author | Blaž Hrastnik | 2021-11-22 07:30:35 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-11-22 07:30:35 +0000 |
commit | 85b4410703fdcf414502daa974061216c64115e8 (patch) | |
tree | 105f9fe84a518e77b2717f56b174ca8857d7e1b9 /helix-term/src/ui | |
parent | 177b6fcdc936c789f85c25a65b4243bde3d53ec3 (diff) |
dap: Toggle breakpoints without changing selection, fix offset calc
Diffstat (limited to 'helix-term/src/ui')
-rw-r--r-- | helix-term/src/ui/editor.rs | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index de2281c6..0e243271 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -985,14 +985,19 @@ impl EditorView { if let Some((coords, view_id)) = result { editor.tree.focus = view_id; - let doc = editor - .documents - .get_mut(&editor.tree.get(view_id).doc) - .unwrap(); - if let Ok(pos) = doc.text().try_line_to_char(coords.row) { - doc.set_selection(view_id, Selection::point(pos)); - commands::dap_toggle_breakpoint(cxt); + let view = editor.tree.get(view_id); + let doc = editor.documents.get_mut(&view.doc).unwrap(); + + let path = match doc.path() { + Some(path) => path.clone(), + None => { + return EventResult::Ignored; + } + }; + let line = coords.row + view.offset.row; + if line < doc.text().len_lines() { + commands::dap_toggle_breakpoint_impl(cxt, path, line); return EventResult::Consumed(None); } } @@ -1087,12 +1092,10 @@ impl EditorView { if let Some((coords, view_id)) = result { cxt.editor.tree.focus = view_id; - let doc = cxt - .editor - .documents - .get_mut(&cxt.editor.tree.get(view_id).doc) - .unwrap(); - if let Ok(pos) = doc.text().try_line_to_char(coords.row) { + let view = cxt.editor.tree.get(view_id); + let doc = cxt.editor.documents.get_mut(&view.doc).unwrap(); + let line = coords.row + view.offset.row; + if let Ok(pos) = doc.text().try_line_to_char(line) { doc.set_selection(view_id, Selection::point(pos)); if modifiers == crossterm::event::KeyModifiers::ALT { commands::Command::dap_edit_log.execute(cxt); |