diff options
| author | Chris Webb <chris@arachsys.com> | 2023-05-11 20:21:31 +0100 |
|---|---|---|
| committer | Chris Webb <chris@arachsys.com> | 2023-05-11 20:21:31 +0100 |
| commit | 2f1e536ac75ddcf9ef4e6fd1c0255c38409b3053 (patch) | |
| tree | 4be8390be26cd846be7830a9a01eb9423710fab8 /src | |
| parent | a69be6288c1a6b1d9fd4468ef11c742b20521d2a (diff) | |
Fix debug keys output for shift/ctrl modified mouse events
Although Kakoune responds to modified mouse events, they show up in the
debug buffer corrupted. to_string() tests for equality on the mouse event
modifiers rather than testing just the relevant bits, so the modified
mouse events incorrectly fall through to the normal key handling.
Fix this and restructure to allow mouse events to be modifier-prefixed.
Signed-off-by: Chris Webb <chris@arachsys.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/keys.cc | 52 |
1 files changed, 24 insertions, 28 deletions
diff --git a/src/keys.cc b/src/keys.cc index db87e48f..2e9b708b 100644 --- a/src/keys.cc +++ b/src/keys.cc @@ -184,37 +184,33 @@ Key::MouseButton str_to_button(StringView str) String to_string(Key key) { const auto coord = key.coord() + DisplayCoord{1,1}; - switch (Key::Modifiers(key.modifiers & ~Key::Modifiers::MouseButtonMask)) - { - case Key::Modifiers::MousePos: - return format("<mouse:move:{}.{}>", coord.line, coord.column); - case Key::Modifiers::MousePress: - return format("<mouse:press:{}:{}.{}>", key.mouse_button(), coord.line, coord.column); - case Key::Modifiers::MouseRelease: - return format("<mouse:release:{}:{}.{}>", key.mouse_button(), coord.line, coord.column); - case Key::Modifiers::Scroll: - return format("<scroll:{}>", static_cast<int>(key.key)); - case Key::Modifiers::Resize: - return format("<resize:{}.{}>", coord.line, coord.column); - default: break; - } - - bool named = false; + bool named = true; String res; - auto it = find_if(keynamemap, [&key](const KeyAndName& item) - { return item.key == key.key; }); - if (it != std::end(keynamemap)) - { - named = true; - res = it->name; - } - else if (key.key >= Key::F1 and key.key <= Key::F12) + + if (key.modifiers & Key::Modifiers::MousePos) + res = format("mouse:move:{}.{}", coord.line, coord.column); + else if (key.modifiers & Key::Modifiers::MousePress) + res = format("mouse:press:{}:{}.{}", key.mouse_button(), coord.line, coord.column); + else if (key.modifiers & Key::Modifiers::MouseRelease) + res = format("mouse:release:{}:{}.{}", key.mouse_button(), coord.line, coord.column); + else if (key.modifiers & Key::Modifiers::Scroll) + res = format("scroll:{}", static_cast<int>(key.key)); + else if (key.modifiers & Key::Modifiers::Resize) + res = format("resize:{}.{}", coord.line, coord.column); + else { - named = true; - res = "F" + to_string((int)(key.key - Key::F1 + 1)); + auto it = find_if(keynamemap, [&key](const KeyAndName& item) + { return item.key == key.key; }); + if (it != std::end(keynamemap)) + res = it->name; + else if (key.key >= Key::F1 and key.key <= Key::F12) + res = "F" + to_string((int)(key.key - Key::F1 + 1)); + else + { + named = false; + res = String{key.key}; + } } - else - res = String{key.key}; if (key.modifiers & Key::Modifiers::Shift) { res = "s-" + res; named = true; } if (key.modifiers & Key::Modifiers::Alt) { res = "a-" + res; named = true; } |
