.TP
.B zoomreset
Reset the zoomlevel to the default value.
+.SS Command-History
+.TP
+.BI [ N "]command-hist-prev [" VALUE "], [" N "]command-hist-next [" VALUE ]
+Prints the \fIprev\fPious or \fInext\fP cammand from history into inputbox. If
+\fIVALUE\fP is given, this will be used as prefix for the inserted command,
+else the default ':' will be used.
.SS Misc
.TP
.BI [ N "]search-{" forward ", " "backward" "}"
{"zoominfull", command_zoom, {COMMAND_ZOOM_IN | COMMAND_ZOOM_FULL}},
{"zoomoutfull", command_zoom, {COMMAND_ZOOM_OUT | COMMAND_ZOOM_FULL}},
{"zoomreset", command_zoom, {COMMAND_ZOOM_RESET}},
+ {"command-hist-next", command_history, {VP_SEARCH_FORWARD, ":"}},
+ {"command-hist-prev", command_history, {VP_SEARCH_BACKWARD, ":"}},
};
static void command_write_input(const char* str);
}
+gboolean command_history(const Arg* arg)
+{
+ State* state = &vp.state;
+ const int len = g_list_length(state->history);
+ char* message = NULL;
+ const int count = state->count ? state->count : 1;
+
+ if (!len) {
+ return FALSE;
+ }
+ if (arg->i == VP_SEARCH_BACKWARD) {
+ state->history_pointer = (len + state->history_pointer - count) % len;
+ } else {
+ state->history_pointer = (len + state->history_pointer + count) % len;
+ }
+
+ const char* command = (char*)g_list_nth_data(state->history, state->history_pointer);
+ message = g_strconcat(arg->s, command, NULL);
+ command_write_input(message);
+ g_free(message);
+
+ return TRUE;
+}
+
static void command_write_input(const char* str)
{
int pos = 0;
gboolean command_search(const Arg* arg);
gboolean command_searchengine(const Arg* arg);
gboolean command_zoom(const Arg* arg);
+gboolean command_history(const Arg* arg);
#endif /* end of include guard: _COMMAND_H */
#define SETTING_MAX_CONNS 25
#define SETTING_MAX_CONNS_PER_HOST 5
+const int COMMAND_HISTORY_SIZE = 30;
+
const struct {
char* command;
} default_config[] = {
{"nmap zz=zoomreset"},
{"cmap <tab>=complete"},
{"cmap <shift-tab>=complete-back"},
+ {"cmap <ctrl-p>=command-hist-prev"},
+ {"cmap <ctrl-n>=command-hist-next"},
{"hmap <tab>=hint-focus-next"},
{"hmap <shift-tab>=hint-focus-prev"},
{"searchengine-add dl=https://duckduckgo.com/lite/?q=%s"},
--- /dev/null
+/**
+ * vimp - a webkit based vim like browser.
+ *
+ * Copyright (C) 2012-2013 Daniel Carl
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://www.gnu.org/licenses/.
+ */
+
+#include "main.h"
+#include "history.h"
+
+extern const int COMMAND_HISTORY_SIZE;
+
+void history_cleanup(void)
+{
+ g_list_free(vp.state.history);
+}
+
+void history_append(const char* line)
+{
+ State *s = &vp.state;
+
+ if (COMMAND_HISTORY_SIZE <= g_list_length(s->history)) {
+ /* if list is too long - remove items from beginning */
+ s->history = g_list_delete_link(s->history, g_list_first(s->history));
+ }
+ s->history = g_list_append(s->history, g_strdup(line));
+}
+
+void history_rewind(void)
+{
+ vp.state.history_pointer = 0;
+}
--- /dev/null
+/**
+ * vimp - a webkit based vim like browser.
+ *
+ * Copyright (C) 2012-2013 Daniel Carl
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://www.gnu.org/licenses/.
+ */
+
+#ifndef _HISTORY_H
+#define _HISTORY_H
+
+void history_cleanup(void);
+void history_append(const char* line);
+void history_rewind(void);
+
+#endif /* end of include guard: _HISTORY_H */
#include "dom.h"
#include "hints.h"
#include "searchengine.h"
+#include "history.h"
/* variables */
static char **args;
success = command_run(token[0], token[1] ? token[1] : NULL);
g_strfreev(token);
+ /* save the command in history */
+ history_append(command);
+
return success;
}
}
switch (CLEAN_MODE(mode)) {
case VP_MODE_NORMAL:
+ /* do this only if the mode is really switched */
+ if (GET_CLEAN_MODE() != VP_MODE_NORMAL) {
+ history_rewind();
+ }
if (GET_CLEAN_MODE() == VP_MODE_HINTING) {
/* if previous mode was hinting clear the hints */
hints_clear();
gboolean is_inspecting;
SearchDirection search_dir;
char* search_query;
+ GList* history;
+ int history_pointer;
} State;
/* behaviour */