From 90acb171fd3092a681ccbf1158d696cff970dc8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Alonso?= <242080768+alvaroalonsoparrondo-a11y@users.noreply.github.com> Date: Thu, 26 Nov 2026 09:57:59 +0100 Subject: [PATCH] fix(input): send no motion report for a drag that stays in its cell MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #834 Signed-off-by: Álvaro Alonso <242080768+alvaroalonsoparrondo-a11y@users.noreply.github.com> --- CHANGELOG.md | 6 ++++++ crates/termlens/src/terminal.rs | 17 ++++++++++------ crates/termlens/tests/input.rs | 36 +++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 710021d2..cf4998fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,12 @@ reads that marker. ### Fixed +- A `drag` whose two ends are the same cell sends a press and a release, + with no motion report between them. It sent one at that cell, but xterm + reports motion only when the pointer enters another cell, so an + application that tells a click from a drag by a motion report saw a drag + where a terminal delivers a click. (#834) + - Both published crates, `termlens` and `termlens-cli`, ship `LICENSE-MIT` and `LICENSE-APACHE`. They are `MIT OR Apache-2.0`, and both licences ask for their text in every copy, but the texts sat only at the repository diff --git a/crates/termlens/src/terminal.rs b/crates/termlens/src/terminal.rs index 51b0ae12..3ddcf1cf 100644 --- a/crates/termlens/src/terminal.rs +++ b/crates/termlens/src/terminal.rs @@ -2598,9 +2598,10 @@ fn cells_between(from: (u16, u16), to: (u16, u16)) -> Vec<(u16, u16)> { let d_row = to_row - from_row; let steps = d_col.abs().max(d_row.abs()); if steps == 0 { - // A drag that goes nowhere still reports the motion it was asked - // for, at the one cell involved. - return vec![to]; + // A drag that stays in its cell crosses none, so it reports no + // motion: xterm sends a motion report only when the pointer enters + // another cell, and the press has already reported this one. + return Vec::new(); } (1..=steps) .map(|step| { @@ -3509,7 +3510,9 @@ impl Terminal { } /// Drag from `(from_col, from_row)` to `(to_col, to_row)`: press, a - /// motion report **per cell crossed**, release. + /// motion report **per cell crossed**, release. A drag whose ends are + /// the same cell crosses none, so it is a press and a release, as a + /// terminal reports a click. /// /// Coordinates are columns first, matching [`click`](Self::click) and /// the other mouse methods. [`Screen::find`](crate::Screen::find) returns @@ -7014,8 +7017,10 @@ mod tests { } #[test] - fn a_drag_that_goes_nowhere_still_reports_one_motion() { - assert_eq!(cells_between((7, 7), (7, 7)), vec![(7, 7)]); + fn a_drag_that_stays_in_its_cell_crosses_none() { + assert_eq!(cells_between((7, 7), (7, 7)), Vec::<(u16, u16)>::new()); + // One cell or more still reports each cell crossed. + assert_eq!(cells_between((7, 7), (8, 7)), vec![(8, 7)]); } /// The endpoints are exact — an off-by-one here would put a drop target diff --git a/crates/termlens/tests/input.rs b/crates/termlens/tests/input.rs index 4ab75c79..98ac876b 100644 --- a/crates/termlens/tests/input.rs +++ b/crates/termlens/tests/input.rs @@ -433,6 +433,42 @@ fn a_drag_reports_one_motion_per_cell_crossed() -> termlens::Result<()> { Ok(()) } +/// A drag that starts and ends in one cell crosses none, so it sends no +/// motion report: xterm reports motion only when the pointer enters another +/// cell (#834). An application that tells a click from a drag by a motion +/// between press and release sees a click. +#[test] +#[cfg_attr( + windows, + ignore = "the wire is read in raw mode, a tcsetattr, and ConPTY turns typed bytes into console events rather than forwarding them (#149)" +)] +fn a_drag_that_stays_in_its_cell_reports_no_motion() -> termlens::Result<()> { + let mut t = util::spawn_emit( + Terminal::builder() + .size(200, 24) + .timeout(Duration::from_secs(10)), + &[ + "--raw-mode", + "--raw", + r"\e[?1002h\e[?1006h", + "READY", + // The `|` follows the read, so waiting for it waits for the wire. + "--read-quiet", + "300", + "|", + "--wait", + ], + )?; + t.wait_until(|s| s.contains("READY"))?; + t.drag(termlens::MouseButton::Left, 6, 1, 6, 1)?; + t.wait_until(|s| s.row_text(0).contains("|"))?; + let text = t.screen().row_text(0); + assert!(!text.contains("[<32;"), "no motion report:\n{text}"); + assert!(text.contains("[<0;7;2M"), "{text}"); + assert!(text.contains("[<0;7;2m"), "{text}"); + Ok(()) +} + /// The mode-aware refusals are untouched: under plain `?1000` the /// application asked not to hear about motion, so it hears none. #[test]