1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-30 03:34:20 +03:00

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.
This commit is contained in:
Enrico Zandomeni Borba 2024-08-04 18:41:49 +02:00
parent e7605b4ec9
commit f2e7498ccc
2 changed files with 2 additions and 3 deletions

View File

@ -7,7 +7,6 @@
#include "utf8_iterator.hh"
#include "utils.hh"
#include "string_utils.hh"
#include "terminal_ui.hh"
namespace Kakoune
{

View File

@ -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> codepoint() const;