From 85b4410703fdcf414502daa974061216c64115e8 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Mon, 22 Nov 2021 16:30:35 +0900 Subject: dap: Toggle breakpoints without changing selection, fix offset calc --- helix-term/src/ui/editor.rs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'helix-term/src/ui') 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); -- cgit v1.2.3-70-g09d2