From: Michael D. Lowis Date: Mon, 10 Oct 2016 01:57:55 +0000 (-0400) Subject: Fix target column tracking for insert mode X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=0bdf5039eca5c9d98e00bf2bb0eed797b1625215;p=projs%2Ftide.git Fix target column tracking for insert mode --- diff --git a/keyboard.c b/keyboard.c index 983320c..b8536e6 100644 --- a/keyboard.c +++ b/keyboard.c @@ -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 b2281b1..a8667f9 100644 --- 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; }