Moved command_history to ex.c
authorDaniel Carl <danielcarl@gmx.de>
Sat, 28 Sep 2013 22:26:24 +0000 (00:26 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Sat, 28 Sep 2013 22:26:24 +0000 (00:26 +0200)
src/command.c
src/command.h
src/ex.c

index 9089f38..958251c 100644 (file)
@@ -80,22 +80,6 @@ gboolean command_search(const Arg *arg)
     return true;
 }
 
-gboolean command_history(const Arg *arg)
-{
-    char *input = vb_get_input_text();
-    char *entry = history_get(input, arg->i);
-    g_free(input);
-
-    if (!entry) {
-        return false;
-    }
-
-    vb_echo_force(VB_MSG_NORMAL, false, "%s", entry);
-    g_free(entry);
-
-    return true;
-}
-
 gboolean command_yank(const Arg *arg)
 {
     static char *tmpl = "Yanked: %s";
index 185ed1c..604583d 100644 (file)
@@ -41,7 +41,6 @@ enum {
 #endif
 
 gboolean command_search(const Arg *arg);
-gboolean command_history(const Arg *arg);
 gboolean command_yank(const Arg *arg);
 gboolean command_save(const Arg *arg);
 #ifdef FEATURE_QUEUE
index c207533..212186e 100644 (file)
--- a/src/ex.c
+++ b/src/ex.c
@@ -112,6 +112,7 @@ static gboolean ex_shortcut(const ExArg *arg);
 
 static gboolean ex_complete(short direction);
 static void ex_completion_select(char *match);
+static gboolean ex_history(short direction);
 
 /* The order of following command names is significant. If there exists
  * ambiguous commands matching to the users input, the first defined will be
@@ -226,12 +227,11 @@ VbResult ex_keypress(unsigned int key)
             break;
 
         case CTRL('P'): /* up */
-            /* TODO don't emit input change event when stepping though history in search mode */
-            command_history(&((Arg){1}));
+            ex_history(-1);
             break;
 
         case CTRL('N'): /* down */
-            command_history(&((Arg){0}));
+            ex_history(1);
             break;
 
         /* basic command line editing */
@@ -969,3 +969,19 @@ static void ex_completion_select(char *match)
     }
     vb_set_input_text(excomp.current);
 }
+
+static gboolean ex_history(short direction)
+{
+    char *input = vb_get_input_text();
+    char *entry = history_get(input, direction < 0);
+    g_free(input);
+
+    if (entry) {
+        vb_set_input_text(entry);
+        g_free(entry);
+
+        return true;
+    }
+
+    return false;
+}