resize terminal pane with mouse
Authored by
mfwolffe <wolffemf@dukes.jmu.edu>
- SHA
04a828122ca11e56941453a9df4cbe3f7253740e- Parents
-
79ef7d3 - Tree
fba04c1
04a8281
04a828122ca11e56941453a9df4cbe3f7253740e79ef7d3
fba04c1| Status | File | + | - |
|---|---|---|---|
| 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 { | ||
| 487 | 487 | last_yank_len: usize, |
| 488 | 488 | /// Integrated terminal panel |
| 489 | 489 | 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, | |
| 490 | 496 | } |
| 491 | 497 | |
| 492 | 498 | impl Editor { |
@@ -539,6 +545,9 @@ impl Editor { | ||
| 539 | 545 | yank_index: None, |
| 540 | 546 | last_yank_len: 0, |
| 541 | 547 | terminal, |
| 548 | + terminal_resize_dragging: false, | |
| 549 | + terminal_resize_start_y: 0, | |
| 550 | + terminal_resize_start_height: 0, | |
| 542 | 551 | }; |
| 543 | 552 | |
| 544 | 553 | // If there are backups, show restore prompt |
@@ -1406,6 +1415,7 @@ impl Editor { | ||
| 1406 | 1415 | && key_event.modifiers.contains(KeyModifiers::CONTROL) |
| 1407 | 1416 | { |
| 1408 | 1417 | let _ = self.terminal.toggle(); |
| 1418 | + self.terminal_resize_dragging = false; | |
| 1409 | 1419 | return Ok(()); |
| 1410 | 1420 | } |
| 1411 | 1421 | |
@@ -1414,6 +1424,7 @@ impl Editor { | ||
| 1414 | 1424 | // ESC hides terminal |
| 1415 | 1425 | if key_event.code == KeyCode::Esc { |
| 1416 | 1426 | self.terminal.hide(); |
| 1427 | + self.terminal_resize_dragging = false; | |
| 1417 | 1428 | return Ok(()); |
| 1418 | 1429 | } |
| 1419 | 1430 | // Send all other keys to terminal |
@@ -1488,6 +1499,34 @@ impl Editor { | ||
| 1488 | 1499 | }; |
| 1489 | 1500 | let text_start_col = left_offset + line_num_width + 1; |
| 1490 | 1501 | |
| 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 | + | |
| 1491 | 1530 | match mouse { |
| 1492 | 1531 | Mouse::Click { button: Button::Left, col, row, modifiers } => { |
| 1493 | 1532 | // Convert screen coordinates to buffer coordinates |
src/input/mouse.rsmodified@@ -37,6 +37,8 @@ pub enum Mouse { | ||
| 37 | 37 | Click { button: Button, col: u16, row: u16, modifiers: MouseModifiers }, |
| 38 | 38 | /// Drag to (column, row) |
| 39 | 39 | Drag { button: Button, col: u16, row: u16, modifiers: MouseModifiers }, |
| 40 | + /// Mouse button released at (column, row) | |
| 41 | + Up { button: Button, col: u16, row: u16 }, | |
| 40 | 42 | /// Scroll up at (column, row) |
| 41 | 43 | ScrollUp { col: u16, row: u16 }, |
| 42 | 44 | /// Scroll down at (column, row) |
@@ -66,9 +68,17 @@ impl Mouse { | ||
| 66 | 68 | }; |
| 67 | 69 | Some(Mouse::Drag { button, col, row, modifiers }) |
| 68 | 70 | } |
| 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 | + } | |
| 69 | 79 | MouseEventKind::ScrollUp => Some(Mouse::ScrollUp { col, row }), |
| 70 | 80 | MouseEventKind::ScrollDown => Some(Mouse::ScrollDown { col, row }), |
| 71 | - _ => None, // Ignore Up, Moved events for now | |
| 81 | + _ => None, // Ignore Moved events for now | |
| 72 | 82 | } |
| 73 | 83 | } |
| 74 | 84 | |
@@ -77,6 +87,7 @@ impl Mouse { | ||
| 77 | 87 | match self { |
| 78 | 88 | Mouse::Click { col, .. } => *col, |
| 79 | 89 | Mouse::Drag { col, .. } => *col, |
| 90 | + Mouse::Up { col, .. } => *col, | |
| 80 | 91 | Mouse::ScrollUp { col, .. } => *col, |
| 81 | 92 | Mouse::ScrollDown { col, .. } => *col, |
| 82 | 93 | } |
@@ -87,6 +98,7 @@ impl Mouse { | ||
| 87 | 98 | match self { |
| 88 | 99 | Mouse::Click { row, .. } => *row, |
| 89 | 100 | Mouse::Drag { row, .. } => *row, |
| 101 | + Mouse::Up { row, .. } => *row, | |
| 90 | 102 | Mouse::ScrollUp { row, .. } => *row, |
| 91 | 103 | Mouse::ScrollDown { row, .. } => *row, |
| 92 | 104 | } |