From: Daniel Carl Date: Sun, 21 Apr 2013 17:04:30 +0000 (+0200) Subject: Reduced the modes. X-Git-Url: https://git.owens.tech/assets/favicon.png/assets/favicon.png/git?a=commitdiff_plain;h=6a9078a39d13f2d77c804bfe205796566da56c37;p=vimb.git Reduced the modes. According to the vim editor, the number of mode of vimb browser are reduced. The previous search mode and hinting mode aren't implemented as main modes with own keybindings, they are now submodes of the normal and command mode instead. This allow to use the already defined keybindings also for the search and hinting mode. For example it's possible to navigate in search mode, that was not possible before. The searching is now more like in vim, where all the navigation commands work in search mode too. Also if the searching is aborted by hitting the search query keeps memorized and could be continued by command search-{forward, backward}. --- diff --git a/doc/vimb.1.txt b/doc/vimb.1.txt index ad4adce..b7d5d3b 100644 --- a/doc/vimb.1.txt +++ b/doc/vimb.1.txt @@ -40,17 +40,8 @@ The default mode. Pressing Escape always enter normal mode. .B Insert Mode Used for editing text elements in a webpage. .TP -.B Hint Mode -Follow links, form fields and frames via hints. -.TP .B Command Mode Execute PROJECT commands from the builtin inputbox (commandline). -.TP -.B Search Mode -Search for strings within the current displayed page. -.TP -.B Insert Mode -Used for editing text elements in a webpage. .SH COMMANDS Commands are a central part in PROJECT. They are used for nearly all things that could be done with this browser. Commands allow to set config variables, @@ -165,7 +156,7 @@ Scroll the page \fIN\fP times the "scrollstep" to the top. .BI [ N "]scrolldown" Scroll the page \fIN\fP times the "scrollstep" to the end. .SS Keybinding -To bind a command to a key sequence use the {n,i,c,h}map command. To map a +To bind a command to a key sequence use the {n,i,c}map command. To map a keysequence to a command, use this format "nmap {[modkey]key}={command}[ params]". The modkey is a single simple char like "g". The key can also contain @@ -174,8 +165,6 @@ special keys and modifiers and is given in format like "", "", Example: .br -"hmap =hint\-focus\-prev" to add focus next in in Hinting Mode. -.br "nmap =input :foo" to write :foo into input box and switch to Command Mode. .br "hunmap " To remove this keybinding use. @@ -193,12 +182,6 @@ Add a keybinding used in Input Mode. .B cmap Add a keybinding used in Command Mode. .TP -.B hmap -Add a keybinding used in Hint Mode. -.TP -.B smap -Add keybinding used in Search Mode. -.TP .B nunmap Remove a Normal Mode keybinding. .TP @@ -208,11 +191,6 @@ Remove a Input Mode keybinding. .B cunmap Remove a Command Mode keybinding. .TP -.B hunmap -Remove a Hint Mode keybinding. -.TP -.B sunmap -Remove a Search Mode keybinding. .SS Complete .TP .B complete @@ -260,7 +238,7 @@ given, print this into the inputbox, default ';i' and ';I'. Start hinting to open inputboxes or textareas with external editor. If \fIPREFIX\fP is given, print this into the inputbox, default ';e'. .TP -.B hint-focus-nex, hint-focus-prevt +.B hint-focus-nex, hint-focus-prev Focus next or previous hint. .SS Yank .TP @@ -510,6 +488,18 @@ Fullcontent Zoom-Out the page by \fIN\fP steps. .TP .B z\-z Reset Zoom. +.TP +.BI [ N ]n +Search for \fIN\fPnth next search result. +.TP +.BI [ N ]N +Search for \fIN\fPnth previous search result. +.TP +.B +Hint to the next element. +.TP +.B +Hint the previous element. .SS COMMAND_MODE .TP .B tab @@ -518,24 +508,17 @@ Complete different sources in the inputbox. .B shift\-tab Complete backward different sources in the inputbox. .TP -.B ctrl\-p, up +.B up Step through hinstory backward. .TP -.B ctrl\-n, down +.B down Step through hinstory forward. .TP -.B tab +.B ctrl\-n Foxus the next hint. .TP -.B shift\-tab +.B ctrl\-p Foxus the previous hint. -.SS SEARCH_MODE -.TP -.BI [ N ]n -Search for \fIN\fPnth next search result. -.TP -.BI [ N ]N -Search for \fIN\fPnth previous search result. .SS INSERT_MODE .TP .B ctrl-t diff --git a/src/command.c b/src/command.c index 8d993bc..0e98c38 100644 --- a/src/command.c +++ b/src/command.c @@ -70,13 +70,9 @@ static CommandInfo cmd_list[] = { {"nmap", command_map, {VB_MODE_NORMAL}}, {"imap", command_map, {VB_MODE_INSERT}}, {"cmap", command_map, {VB_MODE_COMMAND}}, - {"hmap", command_map, {VB_MODE_HINTING}}, - {"smap", command_map, {VB_MODE_SEARCH}}, {"nunmap", command_unmap, {VB_MODE_NORMAL}}, {"iunmap", command_unmap, {VB_MODE_INSERT}}, {"cunmap", command_unmap, {VB_MODE_COMMAND}}, - {"hunmap", command_unmap, {VB_MODE_HINTING}}, - {"sunmap", command_map, {VB_MODE_SEARCH}}, {"set", command_set, {0}}, {"complete", command_complete, {0}}, {"complete-back", command_complete, {1}}, @@ -337,7 +333,8 @@ gboolean command_scroll(const Arg *arg) } gtk_adjustment_set_value(adjust, new > max ? max : new); - vb_set_mode(VB_MODE_NORMAL, false); + /* keep possible search mode */ + vb_set_mode(VB_MODE_NORMAL | (vb.state.mode & VB_MODE_SEARCH), false); return true; } @@ -502,12 +499,10 @@ gboolean command_search(const Arg *arg) { gboolean forward = !(arg->i ^ vb.state.search_dir); - if (arg->i == VB_SEARCH_OFF && vb.state.search_query) { - OVERWRITE_STRING(vb.state.search_query, NULL); + if (arg->i == VB_SEARCH_OFF) { #ifdef FEATURE_SEARCH_HIGHLIGHT webkit_web_view_unmark_text_matches(vb.gui.webview); #endif - return true; } @@ -530,7 +525,7 @@ gboolean command_search(const Arg *arg) } while (--vb.state.count); } - vb_set_mode(VB_MODE_SEARCH, false); + vb_set_mode(VB_MODE_NORMAL | VB_MODE_SEARCH, false); return true; } diff --git a/src/config.h b/src/config.h index 7fc4d5a..68d850c 100644 --- a/src/config.h +++ b/src/config.h @@ -40,8 +40,8 @@ const char *default_config[] = { "nmap =input", "nmap =input /", "nmap =input ?", - "smap n=search-forward", - "smap N=search-backward", + "nmap n=search-forward", + "nmap N=search-backward", "nmap o=input :open ", "nmap t=input :tabopen ", "nmap O=inputuri :open ", @@ -87,12 +87,10 @@ const char *default_config[] = { "nmap zz=zoomreset", "cmap =complete", "cmap =complete-back", - "cmap =hist-prev", + "cmap =hint-focus-prev", + "cmap =hint-focus-next", "cmap =hist-prev", - "cmap =hist-next", "cmap =hist-next", - "hmap =hint-focus-next", - "hmap =hint-focus-prev", "imap =editor", "searchengine-add dl=https://duckduckgo.com/lite/?q=%s", "searchengine-add dd=https://duckduckgo.com/?q=%s", diff --git a/src/hints.c b/src/hints.c index bbab0dd..0f49c2c 100644 --- a/src/hints.c +++ b/src/hints.c @@ -56,7 +56,7 @@ void hints_clear() char *js, *value = NULL; observe_input(false); - if (CLEAN_MODE(vb.state.mode) == VB_MODE_HINTING) { + if (vb.state.mode & VB_MODE_HINTING) { js = g_strdup_printf("%s.clear();", HINT_VAR); vb_eval_script(webkit_web_view_get_main_frame(vb.gui.webview), js, HINT_FILE, &value); g_free(value); @@ -69,8 +69,8 @@ void hints_clear() void hints_create(const char *input, guint mode, const guint prefixLength) { char *js = NULL; - if (CLEAN_MODE(vb.state.mode) != VB_MODE_HINTING) { - vb_set_mode(VB_MODE_HINTING, false); + if (!(vb.state.mode & VB_MODE_HINTING)) { + vb_set_mode(VB_MODE_COMMAND | VB_MODE_HINTING, false); Style *style = &vb.style; hints.prefixLength = prefixLength; diff --git a/src/keybind.c b/src/keybind.c index 91f5a62..98427b6 100644 --- a/src/keybind.c +++ b/src/keybind.c @@ -250,8 +250,8 @@ static gboolean keypress_cb(WebKitWebView *webview, GdkEventKey *event) return true; } - /* allow mode keys and counts only in normal mode */ - if ((VB_MODE_SEARCH | VB_MODE_NORMAL) & vb.state.mode) { + /* allow mode keys and counts only in normal mode and search mode */ + if (vb.state.mode == VB_MODE_NORMAL || vb.state.mode & VB_MODE_SEARCH) { if (vb.state.modkey == 0 && ((keyval >= GDK_1 && keyval <= GDK_9) || (keyval == GDK_0 && vb.state.count))) { /* append the new entered count to previous one */ diff --git a/src/main.c b/src/main.c index d6056c5..e846a88 100644 --- a/src/main.c +++ b/src/main.c @@ -222,20 +222,13 @@ gboolean vb_set_mode(Mode mode, gboolean clean) /* leaf the old mode */ if ((vb.state.mode & VB_MODE_COMPLETE) && !(mode & VB_MODE_COMPLETE)) { completion_clean(); - } - switch (clean_old) { - case VB_MODE_INSERT: - clean = true; - dom_clear_focus(vb.gui.webview); - break; - - case VB_MODE_HINTING: - hints_clear(); - break; - - case VB_MODE_SEARCH: - command_search(&((Arg){VB_SEARCH_OFF})); - break; + } else if ((vb.state.mode & VB_MODE_SEARCH) && !(mode & VB_MODE_SEARCH)) { + command_search(&((Arg){VB_SEARCH_OFF})); + } else if ((vb.state.mode & VB_MODE_HINTING) && !(mode & VB_MODE_HINTING)) { + hints_clear(); + } else if (clean_old == VB_MODE_INSERT) { + clean = true; + dom_clear_focus(vb.gui.webview); } /* enter the new mode */ @@ -246,7 +239,6 @@ gboolean vb_set_mode(Mode mode, gboolean clean) break; case VB_MODE_COMMAND: - case VB_MODE_HINTING: gtk_widget_grab_focus(GTK_WIDGET(vb.gui.inputbox)); break; @@ -255,10 +247,6 @@ gboolean vb_set_mode(Mode mode, gboolean clean) gtk_widget_grab_focus(GTK_WIDGET(vb.gui.webview)); vb_echo(VB_MSG_NORMAL, false, "-- INPUT --"); break; - - case VB_MODE_PATH_THROUGH: - gtk_widget_grab_focus(GTK_WIDGET(vb.gui.webview)); - break; } vb.state.mode = mode; diff --git a/src/main.h b/src/main.h index 7a644f1..fa721c8 100644 --- a/src/main.h +++ b/src/main.h @@ -52,7 +52,7 @@ #endif #define GET_TEXT() (gtk_entry_get_text(GTK_ENTRY(vb.gui.inputbox))) -#define CLEAN_MODE(mode) ((mode) & ~(VB_MODE_COMPLETE)) +#define CLEAN_MODE(mode) ((mode) & ~(VB_MODE_COMPLETE | VB_MODE_SEARCH | VB_MODE_HINTING)) #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) @@ -101,13 +101,14 @@ /* enums */ typedef enum _vb_mode { + /* main modes */ VB_MODE_NORMAL = 1<<0, VB_MODE_COMMAND = 1<<1, - VB_MODE_PATH_THROUGH = 1<<2, - VB_MODE_INSERT = 1<<3, - VB_MODE_SEARCH = 1<<4, - VB_MODE_COMPLETE = 1<<5, - VB_MODE_HINTING = 1<<6, + VB_MODE_INSERT = 1<<2, + /* sub modes */ + VB_MODE_SEARCH = 1<<3, /* normal mode */ + VB_MODE_COMPLETE = 1<<4, /* command mode */ + VB_MODE_HINTING = 1<<5, /* command mode */ } Mode; enum {