Fixed scroll panning

This commit is contained in:
Joshua Barretto 2025-09-30 21:12:34 +01:00
parent cde5905ae0
commit 52b07bfc0b
2 changed files with 5 additions and 26 deletions

View file

@ -20,7 +20,6 @@ pub enum Action {
Char(char), // Insert a character
Indent(bool), // Indent (indent vs deindent)
Move(Dir, Dist, bool, bool), // Move the cursor (dir, dist, retain_base, word)
Pan(Dir, Dist), // Pan the view window
PaneMove(Dir), // Move panes
PaneOpen(Dir), // Create a new pane
PaneClose, // Close the current pane
@ -67,8 +66,7 @@ pub enum Dist {
pub enum MouseAction {
Click,
Drag,
ScrollDown,
ScrollUp,
Scroll(Dir),
}
#[derive(Debug)]
@ -218,19 +216,6 @@ impl RawEvent {
Some(Action::Move(dir, dist, retain_base, word))
}
pub fn to_pan(&self) -> Option<Action> {
let (dir, dist) = match &self.0 {
TerminalEvent::Mouse(ev) => match ev.kind {
MouseEventKind::ScrollUp => (Dir::Up, Dist::Char),
MouseEventKind::ScrollDown => (Dir::Down, Dist::Char),
_ => return None,
},
_ => return None,
};
Some(Action::Pan(dir, dist))
}
pub fn to_select_token(&self) -> Option<Action> {
if matches!(
&self.0,
@ -502,8 +487,8 @@ impl RawEvent {
if let Some(pos) = area.contains([ev.column as isize, ev.row as isize]) {
let action = match ev.kind {
MouseEventKind::ScrollUp => MouseAction::ScrollUp,
MouseEventKind::ScrollDown => MouseAction::ScrollDown,
MouseEventKind::ScrollUp => MouseAction::Scroll(Dir::Up),
MouseEventKind::ScrollDown => MouseAction::Scroll(Dir::Down),
MouseEventKind::Down(MouseButton::Left) => {
*drag_id_counter += 1;
MouseAction::Click

View file

@ -66,7 +66,6 @@ impl Input {
e.to_char()
.map(Action::Char)
.or_else(|| e.to_move())
.or_else(|| e.to_pan())
.or_else(|| e.to_select_token())
.or_else(|| e.to_select_all())
.or_else(|| e.to_indent())
@ -98,13 +97,8 @@ impl Input {
self.refocus(buffer, cursor_id);
Ok(Resp::handled(None))
}
Some(Action::Pan(dir, dist)) if is_doc => {
let dist = match dist {
Dist::Char => [1, 1],
Dist::Page => self.last_area.size().map(|s| s.saturating_sub(3).max(1)),
// TODO: Don't just use an arbitrary very large number
Dist::Doc => [1_000_000_000; 2],
};
Some(Action::Mouse(MouseAction::Scroll(dir), pos, _, _)) if is_doc => {
let dist = [1, 1];
let dfocus = match dir {
Dir::Up => [0, -1],
Dir::Down => [0, 1],