From f2e7498ccc56923b1871278ef4f75e5c0c935b40 Mon Sep 17 00:00:00 2001 From: Enrico Zandomeni Borba Date: Sun, 4 Aug 2024 18:41:49 +0200 Subject: [PATCH] fix mouse coord underflow previously, clicking on the status line if it is on the top of the window results on a coord.line = 1 << 16, or there abouts. This is because the expression (key & 0xFFFF0000) >> 16 results in an `shr` instruction which does not propagate the sign bit. Mouse event coordinates can be negative if the status line is on top and the status line is clicked. The new line (int32_t) (key & 0xFFFF0000) >> 16 properly propagates the sign bit, leading to the correct signed numeric line coordinate. --- src/keys.cc | 1 - src/keys.hh | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/keys.cc b/src/keys.cc index ad66658a4..e08a67092 100644 --- a/src/keys.cc +++ b/src/keys.cc @@ -7,7 +7,6 @@ #include "utf8_iterator.hh" #include "utils.hh" #include "string_utils.hh" -#include "terminal_ui.hh" namespace Kakoune { diff --git a/src/keys.hh b/src/keys.hh index b4796ea5f..3c5d7f4b3 100644 --- a/src/keys.hh +++ b/src/keys.hh @@ -89,9 +89,9 @@ struct Key constexpr bool operator==(Key other) const { return val() == other.val(); } constexpr auto operator<=>(Key other) const { return val() <=> other.val(); } - constexpr DisplayCoord coord() const { return {(int)((key & 0xFFFF0000) >> 16), (int)(key & 0x0000FFFF)}; } + constexpr DisplayCoord coord() const { return {(int)((int32_t) (key & 0xFFFF0000) >> 16), (int)(key & 0x0000FFFF)}; } constexpr MouseButton mouse_button() { return MouseButton{((int)modifiers & (int)Modifiers::MouseButtonMask) >> 6}; } - constexpr int scroll_amount() { return (int)modifiers >> 16; } + constexpr int scroll_amount() { return (int32_t)modifiers >> 16; } static Modifiers to_modifier(MouseButton button) { return Key::Modifiers{((int)button << 6) & (int)Modifiers::MouseButtonMask}; } Optional codepoint() const;