Switch back to normal mode if inputbox is cleared (#55).
authorDaniel Carl <danielcarl@gmx.de>
Mon, 2 Jun 2014 14:54:48 +0000 (16:54 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Mon, 2 Jun 2014 15:36:57 +0000 (17:36 +0200)
src/ex.c

index 243c069..e75a2e8 100644 (file)
--- a/src/ex.c
+++ b/src/ex.c
@@ -224,6 +224,7 @@ void ex_leave(void)
 VbResult ex_keypress(int key)
 {
     GtkTextIter start, end;
+    gboolean check_empty  = false;
     GtkTextBuffer *buffer = vb.gui.buffer;
     GtkTextMark *mark;
     VbResult res;
@@ -281,6 +282,7 @@ VbResult ex_keypress(int key)
                 mark = gtk_text_buffer_get_insert(buffer);
                 gtk_text_buffer_get_iter_at_mark(buffer, &start, mark);
                 gtk_text_buffer_backspace(buffer, &start, true, true);
+                check_empty = true;
                 break;
 
             case CTRL('W'):
@@ -295,6 +297,7 @@ VbResult ex_keypress(int key)
                 if (gtk_text_iter_backward_word_start(&start)) {
                     gtk_text_buffer_delete(buffer, &start, &end);
                 }
+                check_empty = true;
                 break;
 
             case CTRL('B'):
@@ -335,6 +338,16 @@ VbResult ex_keypress(int key)
         }
     }
 
+    /* if the user deleted some content of the inputbox we check if the
+     * inputbox is empty - if so we switch back to normal like vim does */
+    if (check_empty) {
+        gtk_text_buffer_get_bounds(buffer, &start, &end);
+        if (gtk_text_iter_equal(&start, &end)) {
+            mode_enter('n');
+            vb_set_input_text("");
+        }
+    }
+
     if (res == RESULT_COMPLETE) {
         info.cutbuf = 0;
         info.phase  = PHASE_START;