1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Fix behaviour of tabs in raw Bourne Shell-like editing mode

When neither '-o emacs' nor '-o vi' is active, there were a couple
of bugs with entering tab characters:
1. Tab completion was erroneously left active. The cause of this
   was that raw Bourne edit mode is handled by ed_viread() in vi.c
   on shells with wide character support, instead of the default
   ed_read() in edit.c, and the former failed to check if vi mode
   is active when processing tab characters.
2. When entering literal tab characters, the cursor was moved to
   the right only one character, instead of the amount of
   characters corresponding to the tab.

src/cmd/ksh93/edit/vi.c: getline():
- Before processing '\t' (tab) for command completion, check that
  the 'vi' shell option (SH_VI) is active.

src/cmd/ksh93/edit/edit.c: ed_virt_to_phys():
- When translating literal tabs to on-terminal spaces and when
  recalculating the cursor position, remove erroneous checks for
  SH_VI; this is also needed in raw Bourne mode. According to my
  own testing, this has no effect on emacs mode (knock on wood).

src/cmd/ksh93/tests/pty.sh:
- Add two regression tests. An odd race condition reveals itself in
  either pty or in ksh's raw/Bourne edit mode; see comment in test.
  Effect is we have to expect either literal tabs or tabs expanded
  to spaces, until that is tracked down and fixed.

Fixes #43.
This commit is contained in:
Martijn Dekker 2020-06-26 07:19:58 +02:00
parent 4cecde1dd3
commit 8c705bf3b7
4 changed files with 47 additions and 5 deletions

View file

@ -1342,8 +1342,7 @@ int ed_virt_to_phys(Edit_t *ep,genchar *virt,genchar *phys,int cur,int voff,int
if(c=='\t')
{
c = dp-phys;
if(sh_isoption(SH_VI))
c += ep->e_plen;
c += ep->e_plen;
c = TABSIZE - c%TABSIZE;
while(--c>0)
*dp++ = ' ';
@ -1354,8 +1353,7 @@ int ed_virt_to_phys(Edit_t *ep,genchar *virt,genchar *phys,int cur,int voff,int
*dp++ = '^';
c = printchar(c);
}
/* in vi mode the cursor is at the last character */
if(curp == sp && sh_isoption(SH_VI))
if(curp == sp)
r = dp - phys;
}
*dp++ = c;