fix(tui): don't try to add unsupported modifiers (#33799)

Problem:  The TUI doesn't forward a key properly when it has unsupported
          modifiers like NumLock.
Solution: Don't try to add modifiers when only unsupported modifiers are
          present.

Related #33791
This commit is contained in:
zeertzjq
2025-05-03 12:09:28 +08:00
committed by GitHub
parent 862e676efc
commit adbd33027f
2 changed files with 27 additions and 5 deletions

View File

@ -21,6 +21,7 @@
#include "nvim/tui/input_defs.h"
#include "nvim/tui/termkey/driver-csi.h"
#include "nvim/tui/termkey/termkey.h"
#include "nvim/tui/termkey/termkey_defs.h"
#include "nvim/tui/tui.h"
#include "nvim/ui_client.h"
@ -249,6 +250,13 @@ static size_t handle_termkey_modifiers(TermKeyKey *key, char *buf, size_t buflen
return len;
}
enum {
KEYMOD_SUPER = 1 << 3,
KEYMOD_META = 1 << 5,
KEYMOD_RECOGNIZED = (TERMKEY_KEYMOD_SHIFT | TERMKEY_KEYMOD_ALT | TERMKEY_KEYMOD_CTRL
| KEYMOD_SUPER | KEYMOD_META),
};
/// Handle modifiers not handled by libtermkey.
/// Currently only Super ("D-") and Meta ("T-") are supported in Nvim.
///
@ -257,10 +265,10 @@ static size_t handle_more_modifiers(TermKeyKey *key, char *buf, size_t buflen)
FUNC_ATTR_WARN_UNUSED_RESULT
{
size_t len = 0;
if (key->modifiers & 8) { // Super
if (key->modifiers & KEYMOD_SUPER) {
len += (size_t)snprintf(buf + len, buflen - len, "D-");
}
if (key->modifiers & 32) { // Meta
if (key->modifiers & KEYMOD_META) {
len += (size_t)snprintf(buf + len, buflen - len, "T-");
}
assert(len < buflen);
@ -445,7 +453,7 @@ static void tk_getkeys(TermInput *input, bool force)
continue;
}
if (key.type == TERMKEY_TYPE_UNICODE && !key.modifiers) {
if (key.type == TERMKEY_TYPE_UNICODE && !(key.modifiers & KEYMOD_RECOGNIZED)) {
forward_simple_utf8(input, &key);
} else if (key.type == TERMKEY_TYPE_UNICODE
|| key.type == TERMKEY_TYPE_FUNCTION