From d19933bcb1d48ec1ee1c8f1f9822f6204012200d Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Tue, 28 May 2013 20:21:56 +0200 Subject: [PATCH] Fixed wrong mode after calling empty command (#26). If ':' was called from inputbox, vimb kept in command mode so that the normal mode commands and keybindings didn't work. This type of issue is already fixed for empty ':set ' and ':run' commands too. --- src/command.c | 45 ++++++++++++++++++++++++--------------------- src/main.c | 4 ---- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/command.c b/src/command.c index 0c19df1..b9f405c 100644 --- a/src/command.c +++ b/src/command.c @@ -91,7 +91,7 @@ static CommandInfo cmd_list[] = { {"pageup", NULL, command_scroll, {VB_SCROLL_TYPE_SCROLL | VB_SCROLL_DIRECTION_TOP | VB_SCROLL_UNIT_PAGE}}, {"pagedown", NULL, command_scroll, {VB_SCROLL_TYPE_SCROLL | VB_SCROLL_DIRECTION_DOWN | VB_SCROLL_UNIT_PAGE}}, {"halfpageup", NULL, command_scroll, {VB_SCROLL_TYPE_SCROLL | VB_SCROLL_DIRECTION_TOP | VB_SCROLL_UNIT_HALFPAGE}}, - {"halfpagedown", NULL, command_scroll, {VB_SCROLL_TYPE_SCROLL | VB_SCROLL_DIRECTION_DOWN | VB_SCROLL_UNIT_HALFPAGE}}, + {"halfpagedown", NULL, command_scroll, {VB_SCROLL_TYPE_SCROLL | VB_SCROLL_DIRECTION_DOWN | VB_SCROLL_UNIT_HALFPAGE}}, {"scrollleft", NULL, command_scroll, {VB_SCROLL_TYPE_SCROLL | VB_SCROLL_DIRECTION_LEFT | VB_SCROLL_UNIT_LINE}}, {"scrollright", NULL, command_scroll, {VB_SCROLL_TYPE_SCROLL | VB_SCROLL_DIRECTION_RIGHT | VB_SCROLL_UNIT_LINE}}, {"scrollup", NULL, command_scroll, {VB_SCROLL_TYPE_SCROLL | VB_SCROLL_DIRECTION_TOP | VB_SCROLL_UNIT_LINE}}, @@ -195,7 +195,7 @@ gboolean command_run(const char *name, const char *param) } /** - * Runs a single command form string containing the command an possible + * Runs a single command form string containing the command and possible * parameters. */ gboolean command_run_string(const char *input) @@ -203,11 +203,13 @@ gboolean command_run_string(const char *input) gboolean success; char *command = NULL, *str, **token; + vb_set_mode(VB_MODE_NORMAL, false); + if (!input || *input == '\0') { return false; } - str =g_strdup(input); + str = g_strdup(input); /* remove leading whitespace */ g_strchug(str); @@ -237,6 +239,7 @@ gboolean command_run_multi(const Arg *arg) char **commands; unsigned int len, i; + vb_set_mode(VB_MODE_NORMAL, false); if (!arg->s || *(arg->s) == '\0') { return false; } @@ -309,17 +312,19 @@ gboolean command_close(const Arg *arg) gboolean command_view_source(const Arg *arg) { + vb_set_mode(VB_MODE_NORMAL, false); + gboolean mode = webkit_web_view_get_view_source_mode(vb.gui.webview); webkit_web_view_set_view_source_mode(vb.gui.webview, !mode); webkit_web_view_reload(vb.gui.webview); - vb_set_mode(VB_MODE_NORMAL, false); - return true; } gboolean command_navigate(const Arg *arg) { + vb_set_mode(VB_MODE_NORMAL, false); + WebKitWebView *view = vb.gui.webview; if (arg->i <= VB_NAVIG_FORWARD) { int count = vb.state.count ? vb.state.count : 1; @@ -334,8 +339,6 @@ gboolean command_navigate(const Arg *arg) webkit_web_view_stop_loading(view); } - vb_set_mode(VB_MODE_NORMAL, false); - return true; } @@ -345,6 +348,9 @@ gboolean command_scroll(const Arg *arg) int direction = (arg->i & (1 << 2)) ? 1 : -1; GtkAdjustment *adjust = (arg->i & VB_SCROLL_AXIS_H) ? vb.gui.adjust_h : vb.gui.adjust_v; + /* keep possible search mode */ + vb_set_mode(VB_MODE_NORMAL | (vb.state.mode & VB_MODE_SEARCH), false); + max = gtk_adjustment_get_upper(adjust) - gtk_adjustment_get_page_size(adjust); /* type scroll */ if (arg->i & VB_SCROLL_TYPE_SCROLL) { @@ -370,9 +376,6 @@ gboolean command_scroll(const Arg *arg) } gtk_adjustment_set_value(adjust, new > max ? max : new); - /* keep possible search mode */ - vb_set_mode(VB_MODE_NORMAL | (vb.state.mode & VB_MODE_SEARCH), false); - return true; } @@ -404,7 +407,8 @@ gboolean command_set(const Arg *arg) gboolean success; char *param = NULL, *line = NULL; - if (!arg->s || !strlen(arg->s)) { + vb_set_mode(VB_MODE_NORMAL, false); + if (!arg->s || *(arg->s) == '\0') { return false; } @@ -421,8 +425,6 @@ gboolean command_set(const Arg *arg) } g_free(line); - vb_set_mode(VB_MODE_NORMAL, false); - return success; } @@ -555,6 +557,9 @@ gboolean command_search(const Arg *arg) gboolean command_shortcut(const Arg *arg) { gboolean result; + + vb_set_mode(VB_MODE_NORMAL, false); + if (arg->i) { char *handle; @@ -570,8 +575,6 @@ gboolean command_shortcut(const Arg *arg) result = shortcut_remove(arg->s); } - vb_set_mode(VB_MODE_NORMAL, false); - return result; } @@ -587,9 +590,10 @@ gboolean command_zoom(const Arg *arg) float step, level; int count; + vb_set_mode(VB_MODE_NORMAL, false); + if (arg->i & COMMAND_ZOOM_RESET) { webkit_web_view_set_zoom_level(vb.gui.webview, 1.0); - vb_set_mode(VB_MODE_NORMAL, false); return true; } @@ -609,10 +613,7 @@ gboolean command_zoom(const Arg *arg) level + (float)(count *step) * (arg->i & COMMAND_ZOOM_IN ? 1.0 : -1.0) ); - vb_set_mode(VB_MODE_NORMAL, false); - return true; - } gboolean command_history(const Arg *arg) @@ -632,8 +633,9 @@ gboolean command_history(const Arg *arg) gboolean command_bookmark(const Arg *arg) { - bookmark_add(webkit_web_view_get_uri(vb.gui.webview), arg->s); vb_set_mode(VB_MODE_NORMAL, false); + + bookmark_add(webkit_web_view_get_uri(vb.gui.webview), arg->s); return true; } @@ -642,6 +644,8 @@ gboolean command_eval(const Arg *arg) gboolean success; char *value = NULL; + vb_set_mode(VB_MODE_NORMAL, false); + success = vb_eval_script( webkit_web_view_get_main_frame(vb.gui.webview), arg->s, NULL, &value ); @@ -651,7 +655,6 @@ gboolean command_eval(const Arg *arg) vb_echo_force(VB_MSG_ERROR, true, "%s", value); } g_free(value); - vb_set_mode(VB_MODE_NORMAL, false); return success; } diff --git a/src/main.c b/src/main.c index 47741c2..8d790fa 100644 --- a/src/main.c +++ b/src/main.c @@ -464,10 +464,6 @@ static void inputbox_activate_cb(GtkEntry *entry) gtk_widget_grab_focus(GTK_WIDGET(vb.gui.webview)); - if (length <= 1) { - return; - } - /* do not free or modify text */ text = GET_TEXT(); -- 2.20.1