From 698583c24124e9d01db7095259511bf6a8cf547e Mon Sep 17 00:00:00 2001 From: Dmitry Sharshakov Date: Sat, 4 Sep 2021 21:14:24 +0300 Subject: [PATCH] Support setting breakpoints with mouse --- helix-term/src/ui/editor.rs | 17 +++++++++++++++++ helix-view/src/view.rs | 20 ++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 818d275f7..a41a7d641 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -980,6 +980,23 @@ impl EditorView { return EventResult::Consumed(None); } + let result = editor.tree.views().find_map(|(view, _focus)| { + view.gutter_coords_at_screen_coords(row, column) + .map(|coords| (coords.0, coords.1, view.id)) + }); + + if let Some((line, _, view_id)) = result { + editor.tree.focus = view_id; + + let doc = &mut editor.documents[editor.tree.get(view_id).doc]; + if let Ok(pos) = doc.text().try_line_to_char(line) { + doc.set_selection(view_id, Selection::point(pos)); + commands::dap_toggle_breakpoint(cxt); + + return EventResult::Consumed(None); + } + } + EventResult::Ignored } diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index 01f18c719..8a7d33746 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -218,6 +218,26 @@ impl View { pub fn pos_at_screen_coords(&self, doc: &Document, row: u16, column: u16) -> Option { self.text_pos_at_screen_coords(&doc.text().slice(..), row, column, doc.tab_width()) } + + /// Translates screen coordinates into coordinates on the gutter of the view. + /// Returns a tuple of usize typed line and column numbers starting with 0. + /// Returns None if coordinates are not on the gutter. + pub fn gutter_coords_at_screen_coords(&self, row: u16, column: u16) -> Option<(usize, usize)> { + // 1 for status + if row < self.area.top() || row >= self.area.bottom() { + return None; + } + + if column < self.area.left() || column > self.area.right() { + return None; + } + + Some(( + (row - self.area.top()) as usize, + (column - self.area.left()) as usize, + )) + } + // pub fn traverse(&self, text: RopeSlice, start: usize, end: usize, fun: F) // where // F: Fn(usize, usize),