summaryrefslogtreecommitdiff
path: root/Src
diff options
context:
space:
mode:
authorOliver Kiddle <opk@zsh.org>2022-12-16 23:12:54 +0100
committerOliver Kiddle <opk@zsh.org>2022-12-16 23:23:53 +0100
commit7fb6c133bfdf445b4478897adc142ed7d07b5fd6 (patch)
treeca243280f870eefa26da8570f3c808d0a02ddb95 /Src
parent1de8baded2c3f4b8facdaf8f5bc5ffb392e73199 (diff)
downloadzsh-7fb6c133bfdf445b4478897adc142ed7d07b5fd6.tar.gz
zsh-7fb6c133bfdf445b4478897adc142ed7d07b5fd6.zip
51215: consume whole CSI sequences from the input
This affects CSI sequences that aren't explicitly bound but arrive within the usual KEYTIMEOUT time limits. A single undefined-key widget is run instead of unintended bindings for Escape and other characters in the sequence.
Diffstat (limited to 'Src')
-rw-r--r--Src/Zle/zle_keymap.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c
index d90838f03..48691e8d0 100644
--- a/Src/Zle/zle_keymap.c
+++ b/Src/Zle/zle_keymap.c
@@ -1586,7 +1586,7 @@ getkeymapcmd(Keymap km, Thingy *funcp, char **strp)
Thingy func = t_undefinedkey;
char *str = NULL;
int lastlen = 0, lastc = lastchar;
- int timeout = 0;
+ int timeout = 0, csi = 0, startcsi;
keybuflen = 0;
keybuf[0] = 0;
@@ -1636,7 +1636,30 @@ getkeymapcmd(Keymap km, Thingy *funcp, char **strp)
}
#endif
}
- if (!ispfx)
+
+ /* CSI key sequences have a well defined structure so if we currently
+ * have an incomplete one, loop so the rest of it will be included in
+ * the key sequence if that arrives within the timeout. */
+ if (keybuflen >= 3 && !csi) {
+ startcsi = keybuflen - 3;
+ csi = keybuf[startcsi] == '\033' && keybuf[keybuflen - 2] == '[';
+ }
+ if (csi) {
+ csi = keybuf[keybuflen - 2] != Meta && keybuf[keybuflen - 1] >= 0x20
+ && keybuf[keybuflen - 1] <= 0x3f;
+ /* If we reach the end of a valid CSI sequence and the matched key
+ * binding is for part of the CSI introduction, select instead the
+ * undefined-key widget and consume the full sequence from the
+ * input buffer. */
+ if (!csi && keybuf[keybuflen - 1] >= 0x40 &&
+ keybuf[keybuflen - 1] <= 0x7e && lastlen > startcsi &&
+ lastlen <= startcsi + 2) {
+ func = t_undefinedkey;
+ lastlen = keybuflen;
+ }
+ }
+
+ if (!ispfx && !csi)
break;
}
if(!lastlen && keybuflen)