From: Daniel Carl Date: Tue, 6 Aug 2013 19:05:47 +0000 (+0200) Subject: Made pass through mode to a submode (#48). X-Git-Url: https://git.owens.tech/assets/favicon.png/assets/favicon.png/git?a=commitdiff_plain;h=eff58e8523d698eb42a1472ba9e551f12f2f8884;p=vimb.git Made pass through mode to a submode (#48). This allows to use pass through mode together with insert mode. There where also some bugs around the vb_set_mode()'s handling for insert mode, that are now fixed. --- diff --git a/src/command.c b/src/command.c index 92507ee..d1cd64f 100644 --- a/src/command.c +++ b/src/command.c @@ -948,7 +948,14 @@ gboolean command_queue(const Arg *arg) gboolean command_mode(const Arg *arg) { - return vb_set_mode(arg->i, false); + /* if a main mode is given - set the mode like it is */ + if (CLEAN_MODE(arg->i)) { + return vb_set_mode(arg->i, false); + } + + /* else combine the current main mode with the new submode */ + /* TODO move this logic to main.c: vb_set_mode() */ + return vb_set_mode(arg->i|CLEAN_MODE(vb.state.mode), false); } gboolean command_focusinput(const Arg *arg) diff --git a/src/default.h b/src/default.h index a64931b..060e34b 100644 --- a/src/default.h +++ b/src/default.h @@ -90,6 +90,7 @@ static char *default_config[] = { "cmap =hist-prev", "cmap =hist-next", "imap =editor", + "imap =pass-through", "shortcut-add dl=https://duckduckgo.com/html/?q=$0", "shortcut-add dd=https://duckduckgo.com/?q=$0", "shortcut-default dl", diff --git a/src/keybind.c b/src/keybind.c index 59ea62e..ecae4b3 100644 --- a/src/keybind.c +++ b/src/keybind.c @@ -257,7 +257,7 @@ static gboolean keypress_cb(WebKitWebView *webview, GdkEventKey *event) /* skip further logic if we are in pass through mode */ if (vb.state.mode & VB_MODE_PASSTHROUGH) { - return true; + return false; } /* allow mode keys and counts only in normal mode and search mode */ diff --git a/src/main.c b/src/main.c index 09ba47c..90c9bdb 100644 --- a/src/main.c +++ b/src/main.c @@ -196,10 +196,6 @@ gboolean vb_set_clipboard(const Arg *arg) return result; } -/** - * Set the base modes. All other mode flags like completion can be set directly - * to vb.state.mode. - */ gboolean vb_set_mode(Mode mode, gboolean clean) { /* process only if mode has changed */ @@ -211,7 +207,7 @@ gboolean vb_set_mode(Mode mode, gboolean clean) command_search(&((Arg){VB_SEARCH_OFF})); } else if ((vb.state.mode & VB_MODE_HINTING) && !(mode & VB_MODE_HINTING)) { hints_clear(); - } else if (CLEAN_MODE(vb.state.mode) == VB_MODE_INSERT) { + } else if (CLEAN_MODE(vb.state.mode) == VB_MODE_INSERT && !(mode & VB_MODE_INSERT)) { clean = true; dom_clear_focus(vb.gui.webview); } @@ -221,6 +217,10 @@ gboolean vb_set_mode(Mode mode, gboolean clean) case VB_MODE_NORMAL: history_rewind(); gtk_widget_grab_focus(GTK_WIDGET(vb.gui.webview)); + if (mode & VB_MODE_PASSTHROUGH) { + clean = false; + vb_echo(VB_MSG_NORMAL, false, "-- PASS THROUGH --"); + } break; case VB_MODE_COMMAND: @@ -230,13 +230,11 @@ gboolean vb_set_mode(Mode mode, gboolean clean) case VB_MODE_INSERT: clean = false; gtk_widget_grab_focus(GTK_WIDGET(vb.gui.webview)); - vb_echo(VB_MSG_NORMAL, false, "-- INPUT --"); - break; - - case VB_MODE_PASSTHROUGH: - clean = false; - gtk_widget_grab_focus(GTK_WIDGET(vb.gui.webview)); - vb_echo(VB_MSG_NORMAL, false, "-- PASS THROUGH --"); + if (mode & VB_MODE_PASSTHROUGH) { + vb_echo(VB_MSG_NORMAL, false, "-- PASS THROUGH --"); + } else { + vb_echo(VB_MSG_NORMAL, false, "-- INPUT --"); + } break; } vb.state.mode = mode; diff --git a/src/main.h b/src/main.h index 6618191..a4d630a 100644 --- a/src/main.h +++ b/src/main.h @@ -61,7 +61,7 @@ gtk_editable_set_position(GTK_EDITABLE(vb.gui.inputbox), -1); \ } #define GET_URI() (webkit_web_view_get_uri(vb.gui.webview)) -#define CLEAN_MODE(mode) ((mode) & ~(VB_MODE_COMPLETE | VB_MODE_SEARCH | VB_MODE_HINTING)) +#define CLEAN_MODE(mode) ((mode) & (VB_MODE_NORMAL|VB_MODE_COMMAND|VB_MODE_INSERT)) #define CLEAR_INPUT() (vb_echo(VB_MSG_NORMAL, "")) #define PRIMARY_CLIPBOARD() gtk_clipboard_get(GDK_SELECTION_PRIMARY) #define SECONDARY_CLIPBOARD() gtk_clipboard_get(GDK_NONE) @@ -116,8 +116,8 @@ typedef enum _vb_mode { VB_MODE_NORMAL = 1<<0, VB_MODE_COMMAND = 1<<1, VB_MODE_INSERT = 1<<2, - VB_MODE_PASSTHROUGH = 1<<3, /* sub modes */ + VB_MODE_PASSTHROUGH = 1<<3, /* normal or insert mode */ VB_MODE_SEARCH = 1<<4, /* normal mode */ VB_MODE_COMPLETE = 1<<5, /* command mode */ VB_MODE_HINTING = 1<<6, /* command mode */