Scroll sideways with Shift or Alt and the wheel, and in the outline
A wheel that tilts (or a touchpad) already panned the canvas sideways, but only when the terminal passes those events on, and many don't: Windows Terminal only does since 1.24, and Windows' own console layer can drop them. The wheel with Shift held now scrolls sideways too, as in most apps, and so does Alt, since Alacritty and Windows Terminal keep Shift with the mouse for selecting text. The outline scrolls sideways as well (the wheel, zh and zl), for rows wider than its pane: a deep tree or a long title. Clicks land where the rows are, however far they're scrolled, and when the cursor moves its title comes back into view. Fixed on the way: the wheel turned sideways over the help, the menu, a picker or the K card moved it up. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
c587c42115
commit
e6f3c06ecc
8 files changed
+203
-16
No files matched your search
+4
-3
@@ -40,9 +40,10 @@
|
||||
//! again: done. A body is edited the same way, with Enter starting a line.
|
||||
//!
|
||||
//! Mouse: click selects (and focuses a pane), dragging a node moves its
|
||||
//! branch, dragging empty space pans, the wheel scrolls. A double-click on a
|
||||
//! title edits it from that letter. Right-click: the menu. A click on a name
|
||||
//! in the document bar shows that document.
|
||||
//! branch, dragging empty space pans, the wheel scrolls (sideways: a wheel
|
||||
//! that tilts, a touchpad, or Shift or Alt with the wheel). A double-click on
|
||||
//! a title edits it from that letter. Right-click: the menu. A click on a
|
||||
//! name in the document bar shows that document.
|
||||
|
||||
use std::io;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
@@ -7,6 +7,7 @@ use cumulus::input::keymap::DEFAULT_LEADER;
|
||||
use cumulus::model::{Border, CanvasPos, Content, NodeId};
|
||||
use ratatui::Terminal;
|
||||
use ratatui::backend::TestBackend;
|
||||
use ratatui::crossterm::event::{KeyModifiers, MouseEvent, MouseEventKind};
|
||||
|
||||
struct Harness {
|
||||
playground: Playground,
|
||||
@@ -59,6 +60,16 @@ impl Harness {
|
||||
self.mouse(Gesture::RightPress { at: Cell { col, row } });
|
||||
}
|
||||
|
||||
/// A mouse event as the terminal sends it, read the way the event loop
|
||||
/// reads it.
|
||||
fn raw_mouse(&mut self, kind: MouseEventKind, (column, row): (u16, u16), modifiers: KeyModifiers) {
|
||||
let event = MouseEvent { kind, column, row, modifiers };
|
||||
if let Some(gesture) = self.playground.mouse.read(event, Instant::now()) {
|
||||
self.playground.gesture(gesture);
|
||||
}
|
||||
self.draw();
|
||||
}
|
||||
|
||||
/// The focused pane's document.
|
||||
fn doc(&self) -> &Document {
|
||||
self.playground.state.buffers[self.playground.buffer()].doc()
|
||||
@@ -619,3 +630,34 @@ fn more_keys_across_views() {
|
||||
assert_eq!(h.message(), "key hints off");
|
||||
assert!(!h.screen().contains("? help"), "{}", h.screen());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_wheel_scrolls_sideways() {
|
||||
let mut h = Harness::new();
|
||||
let (col, row) = h.find("Watering");
|
||||
// A wheel that tilts, or a touchpad: the canvas pans sideways.
|
||||
h.raw_mouse(MouseEventKind::ScrollRight, (col, row), KeyModifiers::NONE);
|
||||
assert_eq!(h.find("Watering"), (col - 6, row));
|
||||
// Shift or Alt with the wheel: the same, for mice that don't tilt.
|
||||
h.raw_mouse(MouseEventKind::ScrollUp, (col, row), KeyModifiers::SHIFT);
|
||||
assert_eq!(h.find("Watering"), (col, row));
|
||||
h.raw_mouse(MouseEventKind::ScrollDown, (col, row), KeyModifiers::ALT);
|
||||
assert_eq!(h.find("Watering"), (col - 6, row));
|
||||
// The wheel on its own still scrolls up and down.
|
||||
h.raw_mouse(MouseEventKind::ScrollDown, (col, row), KeyModifiers::NONE);
|
||||
assert_eq!(h.find("Watering"), (col - 6, row - 3));
|
||||
|
||||
// The outline, in a narrow pane: rows cut at its edge scroll sideways.
|
||||
h.type_keys("<C-w>v<C-w>v<Space>vogt");
|
||||
assert!(h.screen().contains("outline · Kitchen"));
|
||||
let (col, row) = h.find("Mint, in");
|
||||
h.raw_mouse(MouseEventKind::ScrollRight, (col, row), KeyModifiers::NONE);
|
||||
assert_eq!(h.find("Mint, in"), (col - 6, row), "the wheel sideways");
|
||||
h.type_keys("zh");
|
||||
assert_eq!(h.find("Mint, in"), (col, row), "zh: back");
|
||||
// In a popup, the wheel sideways does nothing (it used to move it up).
|
||||
h.type_keys("?j");
|
||||
let before = h.screen();
|
||||
h.raw_mouse(MouseEventKind::ScrollLeft, (50, 15), KeyModifiers::NONE);
|
||||
assert_eq!(h.screen(), before);
|
||||
}
|
||||
Reference in new issue
Block a user