JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Fixing the return and keypad enter sent characters. Terminals produce \r. And
[st.git] / st.c
diff --git a/st.c b/st.c
index ca4248a..ba93f2f 100644 (file)
--- a/st.c
+++ b/st.c
@@ -59,8 +59,8 @@
 #define STR_ARG_SIZ   16
 #define DRAW_BUF_SIZ  20*1024
 #define UTF_SIZ       4
-#define XK_NO_MOD     UINT_MAX
-#define XK_ANY_MOD    0
+#define XK_ANY_MOD    UINT_MAX
+#define XK_NO_MOD     0
 
 #define REDRAW_TIMEOUT (80*1000) /* 80 ms */
 
@@ -2100,11 +2100,19 @@ tputc(char *c, int len) {
                sel.bx = -1;
        if(IS_SET(MODE_WRAP) && term.c.state & CURSOR_WRAPNEXT)
                tnewline(1); /* always go to first col */
+
+       if(IS_SET(MODE_INSERT) && term.c.x+1 < term.col) {
+               memmove(&term.line[term.c.y][term.c.x+1],
+                       &term.line[term.c.y][term.c.x],
+                       (term.col - term.c.x - 1) * sizeof(Glyph));
+       }
+
        tsetchar(c, &term.c.attr, term.c.x, term.c.y);
-       if(term.c.x+1 < term.col)
+       if(term.c.x+1 < term.col) {
                tmoveto(term.c.x+1, term.c.y);
-       else
+       } else {
                term.c.state |= CURSOR_WRAPNEXT;
+       }
 }
 
 int
@@ -2700,10 +2708,12 @@ kmap(KeySym k, uint state) {
                if(kp->k != k)
                        continue;
 
-               if((state & mask) != mask ||
-                               (mask == XK_NO_MOD && state)) {
+               if(mask == XK_NO_MOD && state)
+                       continue;
+               if(mask != XK_ANY_MOD && mask != XK_NO_MOD && !state)
+                       continue;
+               if((state & mask) != state)
                        continue;
-               }
 
                if((kp->appkey < 0 && IS_SET(MODE_APPKEYPAD)) ||
                                (kp->appkey > 0 && !IS_SET(MODE_APPKEYPAD))) {