tenseleyflow/fackr / 0a83c02

Browse files

fix: Ctrl+D scrolls viewport to show newly added cursor

When using Ctrl+D to select next occurrence, the viewport now scrolls
to show the most recently added cursor instead of staying on the
primary cursor. This makes multi-cursor selection more intuitive as
each new match becomes visible.
Authored by espadonne
SHA
0a83c028a7ff6a0fdf55b57c9d61c35c9c720119
Parents
be7ba4d
Tree
ddb9290

1 changed file

StatusFile+-
M src/editor/state.rs 12 2
src/editor/state.rsmodified
@@ -3606,7 +3606,18 @@ impl Editor {
36063606
         let top_offset = if self.workspace.tabs.len() > 1 { 1 } else { 0 };
36073607
         // Vertical scrolling (2 rows reserved: gap + status bar, plus top_offset for tab bar)
36083608
         let visible_rows = (self.screen.rows as usize).saturating_sub(2 + top_offset);
3609
-        let cursor_line = self.cursor().line;
3609
+
3610
+        // In multi-cursor mode, scroll to the LAST cursor (most recently added)
3611
+        // This ensures Ctrl+D shows the newly found occurrence
3612
+        let cursors = self.cursors();
3613
+        let target_cursor = if cursors.len() > 1 {
3614
+            cursors.all().last().unwrap()
3615
+        } else {
3616
+            cursors.primary()
3617
+        };
3618
+        let cursor_line = target_cursor.line;
3619
+        let cursor_col = target_cursor.col;
3620
+
36103621
         let viewport_line = self.viewport_line();
36113622
 
36123623
         if cursor_line < viewport_line {
@@ -3629,7 +3640,6 @@ impl Editor {
36293640
             .saturating_sub(fuss_width as usize)
36303641
             .saturating_sub(line_num_width + 1);
36313642
 
3632
-        let cursor_col = self.cursor().col;
36333643
         let viewport_col = self.viewport_col();
36343644
 
36353645
         // Keep some margin (3 chars) so cursor isn't right at the edge