]> git.mdlowis.com Git - projs/tide.git/commitdiff
Fix target column tracking for insert mode
authorMichael D. Lowis <mike@mdlowis.com>
Mon, 10 Oct 2016 01:57:55 +0000 (21:57 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Mon, 10 Oct 2016 01:57:55 +0000 (21:57 -0400)
keyboard.c
xedit.c

index 983320c884cd8f2dcaaa233f8f7bf0ce9338acec..b8536e661757013f30d3d8ea415e2635d12a11be 100644 (file)
@@ -34,19 +34,26 @@ static void cursor_end(void) {
     TargetCol = (unsigned)-1;
 }
 
+static void backspace(void) {
+    if (CursorPos == 0) return;
+    buf_del(&Buffer, --CursorPos);
+    TargetCol = buf_getcol(&Buffer, CursorPos);
+}
+
 void handle_key(Rune key) {
     /* ignore invalid keys */
     if (key == RUNE_ERR) return;
     /* handle the special keys */
-    if (0xE000 <= key && key <= 0xF8FF)
+    if (0xE000 <= key && key <= 0xF8FF) {
         special_keys(key);
-    /* Handle regular key */
-    else if (key < 0x20)
+    } else if (key < 0x20) {
         control_keys(key);
-    else if (Buffer.insert_mode)
+    } else if (Buffer.insert_mode) {
         buf_ins(&Buffer, CursorPos++, key);
-    else
+        TargetCol = buf_getcol(&Buffer, CursorPos);
+    } else {
         vi_keys(key);
+    }
 }
 
 static void special_keys(Rune key) {
@@ -67,7 +74,7 @@ static void special_keys(Rune key) {
 static void control_keys(Rune key) {
     switch (key) {
         case KEY_ESCAPE:    Buffer.insert_mode = false;         break;
-        case KEY_BACKSPACE: buf_del(&Buffer, --CursorPos);      break;
+        case KEY_BACKSPACE: backspace();                        break;
         case KEY_CTRL_W:    buf_save(&Buffer);                  break;
         case KEY_CTRL_Q:    exit(0);                            break;
         default:            buf_ins(&Buffer, CursorPos++, key); break;
@@ -75,7 +82,7 @@ static void control_keys(Rune key) {
 }
 
 static void vi_keys(Rune key) {
+    static unsigned count = 0;
     (void)key;
 }
 
-/*****************************************************************************/
diff --git a/xedit.c b/xedit.c
index b2281b19269d2c1adac44c9434612bd894636db4..a8667f9d9aa9d6b0d68d4cfcd65d605f6ab207af 100644 (file)
--- a/xedit.c
+++ b/xedit.c
@@ -250,13 +250,13 @@ int main(int argc, char** argv) {
     init();
     XEvent e;
     while (true) {
-      XPeekEvent(X.display,&e);
-      while (XPending(X.display)) {
-          XNextEvent(X.display, &e);
-          if (!XFilterEvent(&e, None))
-              handle_event(&e);
-      }
-      redraw();
+        XPeekEvent(X.display,&e);
+        while (XPending(X.display)) {
+            XNextEvent(X.display, &e);
+            if (!XFilterEvent(&e, None))
+                handle_event(&e);
+        }
+        redraw();
     }
     return 0;
 }