shithub: vim

Download patch

ref: 67a16248b4538a78e1afcbc7588e16a81f9ea363
parent: 7639ac239ec22b140d0504e09a1a64bb599f2952
author: phil9 <telephil9@gmail.com>
date: Wed Dec 22 16:25:20 EST 2021

fix unicode handling

	although we were handling input as unicode, output
	was done in ascii leading to garbage being printed.
	We now decode runes when printing strings and report
	proper length (not byte but rune count) to fix this.

--- a/os_plan9.c
+++ b/os_plan9.c
@@ -596,9 +596,9 @@
 
 /* Draw normal characters. */
 static int write_str(char *p, int len) {
-    int nbytes;
-    int n;
-    int m;
+    int nbytes, n, m, rn, rl;
+    Rune r;
+
     if (len == 0) {
         return 0;
     }
@@ -609,15 +609,18 @@
             len--, nbytes++)
         ;
     n = nbytes;
+    rl = 0;
     while (n > 0) {
-        m = (curcol + n >= scrollregion.max.x) ?
-            scrollregion.max.x - curcol : n;
+	rn = chartorune(&r, p);
+	rl += rn;
+        m = (curcol + 1 >= scrollregion.max.x) ?
+            scrollregion.max.x - curcol : 1;
         if (m == 0) {
             break;
         }
-        stringnbg(screen, Pt(screen->clipr.min.x + curcol * fontsize.x,
+        runestringnbg(screen, Pt(screen->clipr.min.x + curcol * fontsize.x,
                     screen->clipr.min.y + currow * fontsize.y),
-                fgcolor, ZP, curfont, p, m, bgcolor, ZP);
+                fgcolor, ZP, curfont, &r, 1, bgcolor, ZP);
         curcol += m;
         if (curcol == scrollregion.max.x) {
             curcol = scrollregion.min.x;
@@ -627,10 +630,10 @@
                 currow++;
             }
         }
-        p += m;
-        n -= m;
+        p += rn;
+        n -= rn;
     }
-    return nbytes;
+    return rl;
 }
 
 void mch_write(char_u *p, int len) {
@@ -750,7 +753,7 @@
 	    len = 1;
 	}else
 	    len = runetochar(utf, &rune);
-	add_to_input_buf_csi((char_u*)utf, len); /* TODO escape K_SPECIAL? */
+	add_to_input_buf((char_u*)utf, len); /* TODO escape K_SPECIAL? */
 	return len > 0;
     } else if(ecanmouse()) {
         process_mouse_events();