From 94ca16d9870c937e07d9f646cf60d8bec3e6d828 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 28 Dec 2020 13:44:30 -0800 Subject: [PATCH] gui: round x-coordinate when selecting text But don't round the y-coordinate as that one seems OK. refs: https://github.com/wez/wezterm/issues/350 --- docs/changelog.markdown | 1 + wezterm-gui/src/gui/termwindow.rs | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/changelog.markdown b/docs/changelog.markdown index 2ab45d73e..736bc70c9 100644 --- a/docs/changelog.markdown +++ b/docs/changelog.markdown @@ -35,6 +35,7 @@ brief notes about them may accumulate here. * Windows: fix an issue where VNC-server-emulated AltGr was not treated as AltGr [#392](https://github.com/wez/wezterm/issues/392) * X11: fix an issue where keys that produce unicode characters retained SHIFT as a modifier instead of normalizing it away. [#394](https://github.com/wez/wezterm/issues/394) * Fixed an issue where a symbol-only font would be seen as 0-width and panic wezterm [#404](https://github.com/wez/wezterm/issues/404) +* Tweaked mouse selection: we now round the x-coordinate to the nearest cell which makes it a bit more forgiving if the mouse cursor is slightly to the left of the intended cell start. [#350](https://github.com/wez/wezterm/issues/350) ### 20201101-103216-403d002d diff --git a/wezterm-gui/src/gui/termwindow.rs b/wezterm-gui/src/gui/termwindow.rs index 310bc6e95..05c745913 100644 --- a/wezterm-gui/src/gui/termwindow.rs +++ b/wezterm-gui/src/gui/termwindow.rs @@ -332,12 +332,17 @@ impl WindowCallbacks for TermWindow { }; let config = configuration(); - let x = (event + // Round the x coordinate so that we're a bit more forgiving of + // the horizontal position when selecting cells + let x = ((event .coords .x .sub(config.window_padding.left as isize) - .max(0) - / self.render_metrics.cell_size.width) as usize; + .max(0) as f32) + / self.render_metrics.cell_size.width as f32) + .round() + .trunc() as usize; + // But don't round the y coordinate as that is more annoying let y = (event .coords .y