Re: [patch] ksh: backspace in search-history buffer with UTF8 chars

2022-03-08 Thread Mikhail
On Tue, Mar 08, 2022 at 03:15:55PM +0300, Mikhail wrote:
> Inlined diff helps ksh search-history function (ctrl-r) to handle
> backspace for UTF8 characters properly, without the patch, if I have
> UTF8 characters in my search buffer, I need to press backspace twice to
> push cursor to the left.
> 
> The search itself is not perfect for UTF8 either, sometimes I get
> patterns which are not handled properly, or the input prompt becomes
> mangled, but the issue with backspace is what currently bothers me the
> most.
> 
> Comments, objections?

Better version, behavior is not changed:


diff --git bin/ksh/emacs.c bin/ksh/emacs.c
index 5370e814f70..a5ed4095ae5 100644
--- bin/ksh/emacs.c
+++ bin/ksh/emacs.c
@@ -907,8 +907,11 @@ x_search_hist(int c)
offset = -1;
break;
}
-   if (p > pat)
-   *--p = '\0';
+   if (p > pat) {
+   while (isu8cont(*--p))
+   ;
+   *p ='\0';
+   }
if (p == pat)
offset = -1;
else



[patch] ksh: backspace in search-history buffer with UTF8 chars

2022-03-08 Thread Mikhail
Inlined diff helps ksh search-history function (ctrl-r) to handle
backspace for UTF8 characters properly, without the patch, if I have
UTF8 characters in my search buffer, I need to press backspace twice to
push cursor to the left.

The search itself is not perfect for UTF8 either, sometimes I get
patterns which are not handled properly, or the input prompt becomes
mangled, but the issue with backspace is what currently bothers me the
most.

Comments, objections?

diff --git bin/ksh/emacs.c bin/ksh/emacs.c
index 5370e814f70..0058bad9adb 100644
--- bin/ksh/emacs.c
+++ bin/ksh/emacs.c
@@ -908,7 +908,9 @@ x_search_hist(int c)
break;
}
if (p > pat)
-   *--p = '\0';
+   while (isu8cont(*--p))
+   ;
+   *p ='\0';
if (p == pat)
offset = -1;
else