mirror of
git://git.code.sf.net/p/zsh/code
synced 2024-12-28 04:05:12 +01:00
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.
This commit is contained in:
parent
1de8baded2
commit
7fb6c133bf
4 changed files with 60 additions and 2 deletions
|
@ -1,3 +1,9 @@
|
|||
2022-12-16 Oliver Kiddle <opk@zsh.org>
|
||||
|
||||
* 51215: Src/Zle/zle_keymap.c, Test/X03zlebindkey.ztst,
|
||||
Test/X02zlevi.ztst: consume whole CSI sequences from the input
|
||||
even where they aren't explicitly bound
|
||||
|
||||
2022-12-15 Daniel Shahaf <d.s@daniel.shahaf.name>
|
||||
|
||||
* unposted: Src/zsh.h: Follow-up to the last commit: Fix a typo
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -596,6 +596,13 @@
|
|||
>BUFFER: 1ls `2` $(3) "4" $'5' ${6}
|
||||
>CURSOR: 0
|
||||
|
||||
zpty_run 'bindkey -s -a "cw" "dwi"'
|
||||
zletest $'one two\e0cwyksi'
|
||||
zpty_run 'bindkey -r -a "cw"'
|
||||
0:for a vi command, wait to allow a longer binding to be used
|
||||
>BUFFER: yksitwo
|
||||
>CURSOR: 4
|
||||
|
||||
%clean
|
||||
|
||||
zmodload -ui zsh/zpty
|
||||
|
|
|
@ -37,6 +37,28 @@
|
|||
>"^Xy" "bar"
|
||||
>"^Xy" undefined-key
|
||||
|
||||
zpty_run 'bindkey -s "\e[" altbracket'
|
||||
zletest $'$\C-A\e[17~'
|
||||
zpty_run 'bindkey -r "\e["'
|
||||
0:binding to CSI introduction is not used if a full sequence arrives
|
||||
>BUFFER: $
|
||||
>CURSOR: 0
|
||||
|
||||
zpty_run 'bindkey -s "\e[1" altbracketone'
|
||||
zletest $'$\C-A\e[17~'
|
||||
zpty_run 'bindkey -r "\e[1"'
|
||||
0:binding to longer prefix of a CSI sequence is used
|
||||
# we assume the user knows what they're doing
|
||||
>BUFFER: altbracketone7~$
|
||||
>CURSOR: 15
|
||||
|
||||
zpty_run 'bindkey -s "\e[" altbracket'
|
||||
zletest $'$\C-A\e[177'
|
||||
zpty_run 'bindkey -r "\e["'
|
||||
0:use prefix binding where we don't have a CSI sequence
|
||||
>BUFFER: altbracket177$
|
||||
>CURSOR: 13
|
||||
|
||||
# As we're only looking at definitions here, we don't
|
||||
# bother using the pseudo-terminal; just test in the normal fashion.
|
||||
bindkey -e
|
||||
|
|
Loading…
Reference in a new issue