extern VbCore vb;
-gboolean command_search(const Arg *arg, unsigned int count)
+gboolean command_search(const Arg *arg)
{
- static SearchDirection dir;
+ static short dir; /* last direction 1 forward, -1 backward*/
static char *query = NULL;
#ifdef FEATURE_SEARCH_HIGHLIGHT
static gboolean highlight = false;
#endif
gboolean forward;
- if (arg->i == COMMAND_SEARCH_OFF) {
+ if (arg->i == 0) {
#ifdef FEATURE_SEARCH_HIGHLIGHT
webkit_web_view_unmark_text_matches(vb.gui.webview);
highlight = false;
if (arg->s) {
OVERWRITE_STRING(query, arg->s);
/* set dearch dir only when the searching is started */
- dir = arg->i;
+ dir = arg->i > 0 ? 1 : -1;
}
- forward = !(arg->i ^ dir);
+ forward = (arg->i * dir) > 0;
if (query) {
+ unsigned int count = abs(arg->i);
#ifdef FEATURE_SEARCH_HIGHLIGHT
if (!highlight) {
/* highlight matches if the search is started new or continued
#ifndef _COMMAND_H
#define _COMMAND_H
-typedef enum {
- COMMAND_SEARCH_OFF,
- COMMAND_SEARCH_FORWARD = (1<<0),
- COMMAND_SEARCH_BACKWARD = (1<<1),
-} SearchDirection;
-
enum {
COMMAND_YANK_ARG,
COMMAND_YANK_URI,
};
#endif
-gboolean command_search(const Arg *arg, unsigned int count);
+gboolean command_search(const Arg *arg);
gboolean command_history(const Arg *arg);
gboolean command_yank(const Arg *arg);
gboolean command_save(const Arg *arg);
*/
static void input_activate(void)
{
- gboolean forward = false;
+ int count = -1;
char *text, *cmd;
text = vb_get_input_text();
* does vim also skip history recording for such mapped commands */
cmd = text + 1;
switch (*text) {
- case '/': forward = true; /* fall throught */
+ case '/': count = 1; /* fall throught */
case '?':
history_add(HISTORY_SEARCH, cmd, NULL);
mode_enter('n');
- command_search(&((Arg){forward ? COMMAND_SEARCH_FORWARD : COMMAND_SEARCH_BACKWARD, cmd}), 1);
+ command_search(&((Arg){count, cmd}));
break;
case ';':
void normal_leave(void)
{
/* TODO clean those only if they where active */
- command_search(&((Arg){COMMAND_SEARCH_OFF}), 0);
+ command_search(&((Arg){0}));
}
/**
{
vb_set_input_text("");
gtk_widget_grab_focus(GTK_WIDGET(vb.gui.webview));
- command_search(&((Arg){COMMAND_SEARCH_OFF}), 0);
+ command_search(&((Arg){0}));
return RESULT_COMPLETE;
}
static VbResult normal_search(const NormalCmdInfo *info)
{
- command_search(
- &((Arg){info->cmd == 'n' ? COMMAND_SEARCH_FORWARD : COMMAND_SEARCH_BACKWARD}),
- info->count > 0 ? info->count : 1
- );
+ int count = (info->count > 0) ? info->count : 1;
+
+ command_search(&((Arg){info->cmd == 'n' ? count : -count}));
return RESULT_COMPLETE;
}
static VbResult normal_search_selection(const NormalCmdInfo *info)
{
+ int count;
+ char *query;
+
/* there is no function to get the selected text so we copy current
* selection to clipboard */
webkit_web_view_copy_clipboard(vb.gui.webview);
- char *query = gtk_clipboard_wait_for_text(PRIMARY_CLIPBOARD());
+ query = gtk_clipboard_wait_for_text(PRIMARY_CLIPBOARD());
if (!query) {
return RESULT_ERROR;
}
+ count = (info->count > 0) ? info->count : 1;
- command_search(
- &((Arg){info->cmd == '*' ? COMMAND_SEARCH_FORWARD : COMMAND_SEARCH_BACKWARD, query}),
- info->count > 0 ? info->count : 1
- );
+ command_search(&((Arg){info->cmd == '*' ? count : -count}));
g_free(query);
return RESULT_COMPLETE;