Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions crates/termlens/src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions crates/termlens/tests/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading