on master help sign in
Support setting breakpoints with mouse
commit698583c24124e9d01db7095259511bf6a8cf547e authorDmitry Sharshakov <d3dx12.xx@gmail.com> dateSat 4 Sep 2021, 21:14 (5 years ago) parentdf0ea66
2 files changed+37
helix-term/src/ui/editor.rs+17 helix-view/src/view.rs+20
helix-term/src/ui/editor.rs+17
@@ -980,6 +980,23 @@ impl EditorView {
980980 return EventResult::Consumed(None);
981981 }
982982
983+ let result = editor.tree.views().find_map(|(view, _focus)| {
984+ view.gutter_coords_at_screen_coords(row, column)
985+ .map(|coords| (coords.0, coords.1, view.id))
986+ });
987+
988+ if let Some((line, _, view_id)) = result {
989+ editor.tree.focus = view_id;
990+
991+ let doc = &mut editor.documents[editor.tree.get(view_id).doc];
992+ if let Ok(pos) = doc.text().try_line_to_char(line) {
993+ doc.set_selection(view_id, Selection::point(pos));
994+ commands::dap_toggle_breakpoint(cxt);
995+
996+ return EventResult::Consumed(None);
997+ }
998+ }
999+
9831000 EventResult::Ignored
9841001 }
9851002
helix-view/src/view.rs+20
@@ -218,6 +218,26 @@ impl View {
218218 pub fn pos_at_screen_coords(&self, doc: &Document, row: u16, column: u16) -> Option<usize> {
219219 self.text_pos_at_screen_coords(&doc.text().slice(..), row, column, doc.tab_width())
220220 }
221+
222+ /// Translates screen coordinates into coordinates on the gutter of the view.
223+ /// Returns a tuple of usize typed line and column numbers starting with 0.
224+ /// Returns None if coordinates are not on the gutter.
225+ pub fn gutter_coords_at_screen_coords(&self, row: u16, column: u16) -> Option<(usize, usize)> {
226+ // 1 for status
227+ if row < self.area.top() || row >= self.area.bottom() {
228+ return None;
229+ }
230+
231+ if column < self.area.left() || column > self.area.right() {
232+ return None;
233+ }
234+
235+ Some((
236+ (row - self.area.top()) as usize,
237+ (column - self.area.left()) as usize,
238+ ))
239+ }
240+
221241 // pub fn traverse<F>(&self, text: RopeSlice, start: usize, end: usize, fun: F)
222242 // where
223243 // F: Fn(usize, usize),