aboutsummaryrefslogtreecommitdiff
path: root/src/app/state.rs
diff options
context:
space:
mode:
authorleeeanh <44962286+leeeanh@users.noreply.github.com>2026-05-17 19:05:30 +0700
committerGitHub <noreply@github.com>2026-05-17 15:05:30 +0300
commit45a4318bbbcb2c91d95faee6f31e5846ae3f9ec0 (patch)
tree0b5f9b8f5b3dfb81a5f2fe4672e148fcbd58473b /src/app/state.rs
parentf4008dc97a60fb6ce9e75b8b521b21ab38f6ad61 (diff)
feat: add selection autoscroll and fix stale selection on transitions (#129)
When dragging to select text near pane edges, a 30ms recurring tick now continues scrolling and extending the selection while the mouse is idle. The autoscroll stops on MouseUp, key input, navigate action, cursor leaving the hot zone, scrollback boundary, missing metrics, or pane rect change. Also fixes pre-existing bugs where workspace/tab/pane transitions failed to clear selection state, which could cause stale selections to persist across views. Selection clearing on pane death is scoped to only the dying pane. Also fixes anchor_screen_pos returning pane-relative coordinates instead of screen coordinates, which caused false drag detection and spurious edge autoscroll on same-cell events when the pane has a non-zero origin. refs #128 Co-authored-by: leeanh <mac@macs-MacBook-Pro.local>
Diffstat (limited to 'src/app/state.rs')
-rw-r--r--src/app/state.rs29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/app/state.rs b/src/app/state.rs
index 10631157..1a2bbddf 100644
--- a/src/app/state.rs
+++ b/src/app/state.rs
@@ -5,6 +5,31 @@ use ratatui::style::Color;
use crate::layout::{PaneId, PaneInfo, SplitBorder};
use crate::selection::Selection;
+
+// ---------------------------------------------------------------------------
+// Selection autoscroll types
+// ---------------------------------------------------------------------------
+
+/// Direction of automatic scrolling during text selection drag.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub(crate) enum SelectionAutoscrollDirection {
+ Up,
+ Down,
+}
+
+/// State for automatic scrolling during text selection drag.
+///
+/// When the cursor hovers in the 1-row hot zone at the top or bottom edge
+/// of a pane (or outside the pane), this struct captures the direction and
+/// last known mouse position so a recurring 30ms tick can continue scrolling
+/// and extending the selection even when the mouse is not moving.
+#[derive(Clone, Debug)]
+pub(crate) struct SelectionAutoscroll {
+ pub direction: SelectionAutoscrollDirection,
+ pub last_mouse_screen_col: u16,
+ pub last_mouse_screen_row: u16,
+ pub inner_rect: Rect,
+}
use crate::terminal_theme::TerminalTheme;
use crate::workspace::Workspace;
@@ -862,6 +887,7 @@ pub struct AppState {
pub(crate) workspace_press: Option<WorkspacePressState>,
pub(crate) tab_press: Option<TabPressState>,
pub selection: Option<Selection>,
+ pub selection_autoscroll: Option<SelectionAutoscroll>,
pub context_menu: Option<ContextMenuState>,
// Notifications
pub update_available: Option<String>,
@@ -936,7 +962,7 @@ impl AppState {
&& self
.active
.and_then(|idx| self.focused_runtime_in_workspace(idx))
- .and_then(crate::pane::PaneRuntime::input_state)
+ .and_then(crate::terminal::TerminalRuntime::input_state)
.is_some_and(crate::pane::InputState::mouse_reporting_enabled)
}
@@ -1107,6 +1133,7 @@ impl AppState {
workspace_press: None,
tab_press: None,
selection: None,
+ selection_autoscroll: None,
context_menu: None,
update_available: None,
update_install_command: "herdr update".into(),