From 006f465d1bf4a37c8470028bc47876b5f5f4c272 Mon Sep 17 00:00:00 2001 From: Jenia Dysin Date: Sat, 23 Aug 2025 13:40:19 +0000 Subject: [PATCH] Add ability to select single/multiple line(s) by clicking the line number and or dragging across --- src/tui.rs | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/src/tui.rs b/src/tui.rs index 78308f0d679..58749a6e6b0 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -2312,11 +2312,46 @@ impl<'a> Context<'a, '_> { } } } + // Clicking on the left margin (gutter) should select the whole line. + let margin_rect = Rect { + left: inner.left, + top: inner.top, + right: inner.left + tb.margin_width(), + bottom: inner.bottom, + }; - self.set_input_consumed(); - return make_cursor_visible; - } + if margin_rect.contains(self.tui.mouse_down_position) { + // If the user is dragging the mouse after pressing in the margin, + // update the selection to span from the initial click line to the current mouse line. + if self.tui.mouse_is_drag { + // Ensure there's a selection anchor at the original cursor position. + if !tb.has_selection() { + tb.start_selection(); + } + let drag_pos = Point { x: 0, y: pos.y }; + tb.selection_update_visual(drag_pos); + tc.preferred_column = tb.cursor_visual_pos().x; + make_cursor_visible = true; + } else { + // Single click: either extend selection (Shift) or select the clicked line. + let click_pos = pos; + if self.input_mouse_modifiers.contains(kbmod::SHIFT) { + tb.selection_update_visual(click_pos); + } else { + tb.cursor_move_to_visual(click_pos); + tb.select_line(); + } + + tc.preferred_column = tb.cursor_visual_pos().x; + make_cursor_visible = true; + } + + // Consume input once and return. + self.set_input_consumed(); + return make_cursor_visible; + } + } if !tc.has_focus { return false; }