tenseleyflow/fackr / 04a8281

Browse files

resize terminal pane with mouse

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
04a828122ca11e56941453a9df4cbe3f7253740e
Parents
79ef7d3
Tree
fba04c1

2 changed files

StatusFile+-
M src/editor/state.rs 39 0
M src/input/mouse.rs 13 1
src/editor/state.rsmodified
@@ -487,6 +487,12 @@ pub struct Editor {
487487
     last_yank_len: usize,
488488
     /// Integrated terminal panel
489489
     terminal: TerminalPanel,
490
+    /// Terminal resize: dragging in progress
491
+    terminal_resize_dragging: bool,
492
+    /// Terminal resize: starting Y position of drag
493
+    terminal_resize_start_y: u16,
494
+    /// Terminal resize: starting height when drag began
495
+    terminal_resize_start_height: u16,
490496
 }
491497
 
492498
 impl Editor {
@@ -539,6 +545,9 @@ impl Editor {
539545
             yank_index: None,
540546
             last_yank_len: 0,
541547
             terminal,
548
+            terminal_resize_dragging: false,
549
+            terminal_resize_start_y: 0,
550
+            terminal_resize_start_height: 0,
542551
         };
543552
 
544553
         // If there are backups, show restore prompt
@@ -1406,6 +1415,7 @@ impl Editor {
14061415
             && key_event.modifiers.contains(KeyModifiers::CONTROL)
14071416
         {
14081417
             let _ = self.terminal.toggle();
1418
+            self.terminal_resize_dragging = false;
14091419
             return Ok(());
14101420
         }
14111421
 
@@ -1414,6 +1424,7 @@ impl Editor {
14141424
             // ESC hides terminal
14151425
             if key_event.code == KeyCode::Esc {
14161426
                 self.terminal.hide();
1427
+                self.terminal_resize_dragging = false;
14171428
                 return Ok(());
14181429
             }
14191430
             // Send all other keys to terminal
@@ -1488,6 +1499,34 @@ impl Editor {
14881499
         };
14891500
         let text_start_col = left_offset + line_num_width + 1;
14901501
 
1502
+        // Handle terminal resize dragging
1503
+        if self.terminal.visible {
1504
+            let title_row = self.screen.rows.saturating_sub(self.terminal.height);
1505
+
1506
+            match mouse {
1507
+                Mouse::Click { button: Button::Left, row, .. } if row == title_row => {
1508
+                    // Start dragging on title bar
1509
+                    self.terminal_resize_dragging = true;
1510
+                    self.terminal_resize_start_y = row;
1511
+                    self.terminal_resize_start_height = self.terminal.height;
1512
+                    return Ok(());
1513
+                }
1514
+                Mouse::Drag { button: Button::Left, row, .. } if self.terminal_resize_dragging => {
1515
+                    // Resize while dragging
1516
+                    let delta = self.terminal_resize_start_y as i32 - row as i32;
1517
+                    let new_height = (self.terminal_resize_start_height as i32 + delta).max(3) as u16;
1518
+                    self.terminal.resize_height(new_height);
1519
+                    return Ok(());
1520
+                }
1521
+                Mouse::Up { button: Button::Left, .. } if self.terminal_resize_dragging => {
1522
+                    // Stop dragging
1523
+                    self.terminal_resize_dragging = false;
1524
+                    return Ok(());
1525
+                }
1526
+                _ => {}
1527
+            }
1528
+        }
1529
+
14911530
         match mouse {
14921531
             Mouse::Click { button: Button::Left, col, row, modifiers } => {
14931532
                 // Convert screen coordinates to buffer coordinates
src/input/mouse.rsmodified
@@ -37,6 +37,8 @@ pub enum Mouse {
3737
     Click { button: Button, col: u16, row: u16, modifiers: MouseModifiers },
3838
     /// Drag to (column, row)
3939
     Drag { button: Button, col: u16, row: u16, modifiers: MouseModifiers },
40
+    /// Mouse button released at (column, row)
41
+    Up { button: Button, col: u16, row: u16 },
4042
     /// Scroll up at (column, row)
4143
     ScrollUp { col: u16, row: u16 },
4244
     /// Scroll down at (column, row)
@@ -66,9 +68,17 @@ impl Mouse {
6668
                 };
6769
                 Some(Mouse::Drag { button, col, row, modifiers })
6870
             }
71
+            MouseEventKind::Up(button) => {
72
+                let button = match button {
73
+                    MouseButton::Left => Button::Left,
74
+                    MouseButton::Right => Button::Right,
75
+                    MouseButton::Middle => Button::Middle,
76
+                };
77
+                Some(Mouse::Up { button, col, row })
78
+            }
6979
             MouseEventKind::ScrollUp => Some(Mouse::ScrollUp { col, row }),
7080
             MouseEventKind::ScrollDown => Some(Mouse::ScrollDown { col, row }),
71
-            _ => None, // Ignore Up, Moved events for now
81
+            _ => None, // Ignore Moved events for now
7282
         }
7383
     }
7484
 
@@ -77,6 +87,7 @@ impl Mouse {
7787
         match self {
7888
             Mouse::Click { col, .. } => *col,
7989
             Mouse::Drag { col, .. } => *col,
90
+            Mouse::Up { col, .. } => *col,
8091
             Mouse::ScrollUp { col, .. } => *col,
8192
             Mouse::ScrollDown { col, .. } => *col,
8293
         }
@@ -87,6 +98,7 @@ impl Mouse {
8798
         match self {
8899
             Mouse::Click { row, .. } => *row,
89100
             Mouse::Drag { row, .. } => *row,
101
+            Mouse::Up { row, .. } => *row,
90102
             Mouse::ScrollUp { row, .. } => *row,
91103
             Mouse::ScrollDown { row, .. } => *row,
92104
         }