summaryrefslogtreecommitdiff
path: root/src/command.c
diff options
context:
space:
mode:
authorDaniel Carl <danielcarl@gmx.de>2013-02-24 20:24:05 +0100
committerDaniel Carl <danielcarl@gmx.de>2013-02-24 20:24:05 +0100
commit880612a9dc867edd0cabb71086a42cec46963894 (patch)
treee4341a0be2f581217be687749841062fee2fef58 /src/command.c
parent4404ba3667a34bcc6343b0e3dc15415bbdb979d0 (diff)
Implemented prefix aware history searching (#7).
If ':set' is already typed in the inputbox, the history will only step over those items that matches this prefix. Now vimp behave a little bit more like the great vim editor.
Diffstat (limited to 'src/command.c')
-rw-r--r--src/command.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/src/command.c b/src/command.c
index 02398a6..3a96bdb 100644
--- a/src/command.c
+++ b/src/command.c
@@ -25,6 +25,7 @@
#include "hints.h"
#include "util.h"
#include "searchengine.h"
+#include "history.h"
static CommandInfo cmd_list[] = {
/* command function arg mode */
@@ -529,23 +530,17 @@ gboolean command_zoom(const Arg* arg)
gboolean command_history(const Arg* arg)
{
- const int len = g_list_length(core.behave.history);
- char* message = NULL;
+ char* msg = NULL;
const int count = vp.state.count ? vp.state.count : 1;
+ const gint step = count * (arg->i == VP_SEARCH_BACKWARD ? -1 : 1);
+ const char* entry = history_get(step);
- if (!len) {
+ if (!entry) {
return FALSE;
}
- if (arg->i == VP_SEARCH_BACKWARD) {
- core.behave.history_pointer = (len + core.behave.history_pointer - count) % len;
- } else {
- core.behave.history_pointer = (len + core.behave.history_pointer + count) % len;
- }
-
- const char* command = (char*)g_list_nth_data(core.behave.history, core.behave.history_pointer);
- message = g_strconcat(arg->s, command, NULL);
- command_write_input(message);
- g_free(message);
+ msg = g_strconcat(arg->s, entry, NULL);
+ command_write_input(msg);
+ g_free(msg);
return TRUE;
}