1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-13 11:42:21 +00:00

emacs: fix keys w/ repeat parameters repeating extra (re: 29b11bba)

@JohnoKing writes:
> In emacs mode, using Alt+D or Alt+H with a repeat parameter
> results in the deletion of extra characters. Reproducer:
>
> $ set -o emacs
> $ foo bar delete add   # <Ctrl+A> <ESC+3+Alt+D>
> $ d  # Should be ' add'
>
> $ foo bar delete add   # <ESC+3+Alt+H>
> $ f  # Should be 'foo '
>
> [...] this bug also affects the Delete and Arrow keys [...].
> Reproducer:
>
> $ test_string <Ctrl+A> <ESC+3+Delete>
>	# This will delete all of 'test', which is four characters
> $ test_string <Ctrl+A> <ESC+4+Right Arrow>
>	# This should move the cursor to '_', not 's'

src/cmd/ksh93/edit/emacs.c: ed_emacsread():
- Revert part of 29b11bba: once again set 'count' to
  'vt220_save_repeat' instead of adding the value.
- do_escape: If the escape() function (which handles both ESC
  repeat counts and commands like ESC d and ESC h) returns a repeat
  count, do not use the saved repeat count for v220 sequences.

src/cmd/ksh93/tests/pty.sh:
- Test the four reproducers above.

Fixes: https://github.com/ksh93/ksh/issues/292
This commit is contained in:
Martijn Dekker 2021-05-04 05:10:32 +01:00
parent da4bf85f27
commit 143ff27a91
2 changed files with 23 additions and 1 deletions

View file

@ -324,7 +324,7 @@ int ed_emacsread(void *context, int fd,char *buff,int scend, int reedit)
count = 1;
if(vt220_save_repeat>0)
{
count += vt220_save_repeat;
count = vt220_save_repeat;
vt220_save_repeat = 0;
}
adjust = -1;
@ -623,6 +623,8 @@ update:
vt220_save_repeat = oadjust;
do_escape:
adjust = escape(ep,out,oadjust);
if(adjust > -1)
vt220_save_repeat = 0;
continue;
case cntl('R') :
search(ep,out,count);

View file

@ -872,5 +872,25 @@ w `echo true`\t
r ^:test-2: `echo true`\r\n$
!
# err_exit #
((SHOPT_ESH)) && VISUAL=emacs tst $LINENO <<"!"
L emacs: keys with repeat parameters repeat extra steps
# https://github.com/ksh93/ksh/issues/292
d 15
p :test-1:
w : foo bar delete add\1\6\6\E3\Ed
r ^:test-1: : add\r\n$
p :test-2:
w : foo bar delete add\E3\Eh
r ^:test-2: : foo \r\n$
p :test-3:
w : test_string\1\6\6\E3\E[3~
r ^:test-3: : t_string\r\n$
p :test-4:
w : test_string\1\E6\E[C\4
r ^:test-4: : teststring\r\n$
!
# ======
exit $((Errors<125?Errors:125))