gardesk/garterm / 2b684a0

Browse files

feat: auto-scroll when dragging selection outside window bounds

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
2b684a0823bcd8a2010226550dd945df26fa7e5a
Parents
0c9f13c
Tree
9cc7efe

1 changed file

StatusFile+-
M garterm/src/app.rs 31 7
garterm/src/app.rsmodified
@@ -1664,17 +1664,41 @@ impl App {
16641664
             }
16651665
         }
16661666
 
1667
-        // Update selection during drag
1667
+        // Update selection during drag (with auto-scroll when outside bounds)
16681668
         if self.selection.is_active() && state & 0x100 != 0 {
1669
-            if let Some(pane) = self.tabs.focused_pane() {
1670
-                // Convert viewport row to absolute row
1669
+            if let Some(pane) = self.tabs.focused_pane_mut() {
1670
+                let rows = pane.terminal.rows();
1671
+                let content_height = (rows as f32 * cell_h) as i16;
1672
+                let raw_y = event.event_y - content_offset;
1673
+
1674
+                // Check if mouse is outside content bounds
1675
+                if raw_y < 0 {
1676
+                    // Mouse above content - scroll up into scrollback
1677
+                    let scroll_amount = ((-raw_y) as usize / cell_h as usize).max(1).min(5);
1678
+                    pane.terminal.scroll_up(scroll_amount);
1679
+
1680
+                    // Update selection to top visible row
1681
+                    let abs_row = pane.terminal.grid().visible_row_to_absolute(0);
1682
+                    self.selection.update(abs_row, col);
1683
+                    pane.mark_dirty();
1684
+                } else if raw_y > content_height {
1685
+                    // Mouse below content - scroll down (toward bottom)
1686
+                    let overshoot = (raw_y - content_height) as usize;
1687
+                    let scroll_amount = (overshoot / cell_h as usize).max(1).min(5);
1688
+                    pane.terminal.scroll_down(scroll_amount);
1689
+
1690
+                    // Update selection to bottom visible row
1691
+                    let abs_row = pane.terminal.grid().visible_row_to_absolute(rows.saturating_sub(1));
1692
+                    self.selection.update(abs_row, col);
1693
+                    pane.mark_dirty();
1694
+                } else {
1695
+                    // Normal case - mouse within bounds
16711696
                     let abs_row = pane.terminal.grid().visible_row_to_absolute(row);
16721697
                     self.selection.update(abs_row, col);
1673
-            }
1674
-            if let Some(pane) = self.tabs.focused_pane_mut() {
16751698
                     pane.mark_dirty();
16761699
                 }
16771700
             }
1701
+        }
16781702
 
16791703
         Ok(())
16801704
     }