diff --git a/CHANGELOG.md b/CHANGELOG.md index d4569c1..8ba1966 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -70,6 +70,11 @@ reads that marker. cursor, and any nonzero `U=` makes the placement virtual, so it does not; termlens took `P=` by its presence and `U=` only at 1, so the text a client wrote after `P=0` landed on the image. (#844) +- 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 51b0ae1..3ddcf1c 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 4ab75c7..98ac876 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]