From: Daniel Carl Date: Thu, 25 Jul 2013 09:54:54 +0000 (+0200) Subject: Better search performance on large pages. X-Git-Url: https://git.owens.tech/wrapped.html/wrapped.html/git?a=commitdiff_plain;h=270ba4253237a5c244c5d49b60a8424bdc013d59;p=vimb.git Better search performance on large pages. Don't highlight the matches every time we search for the next occurrence of search string on page, it's neough to do it if the search is started. Removed search related variables from global struct. --- diff --git a/src/command.c b/src/command.c index 466a2e5..89c45bc 100644 --- a/src/command.c +++ b/src/command.c @@ -568,32 +568,48 @@ gboolean command_paste(const Arg *arg) gboolean command_search(const Arg *arg) { + static SearchDirection dir; + static char *query = NULL; +#ifdef FEATURE_SEARCH_HIGHLIGHT + static gboolean highlight = false; +#endif gboolean forward; if (arg->i == VB_SEARCH_OFF) { #ifdef FEATURE_SEARCH_HIGHLIGHT webkit_web_view_unmark_text_matches(vb.gui.webview); + highlight = false; #endif return true; } /* copy search query for later use */ if (arg->s) { - OVERWRITE_STRING(vb.state.search_query, arg->s); + OVERWRITE_STRING(query, arg->s); /* set dearch dir only when the searching is started */ - vb.state.search_dir = arg->i; + dir = arg->i; } - forward = !(arg->i ^ vb.state.search_dir); - if (vb.state.search_query) { + forward = !(arg->i ^ dir); + + if (query) { #ifdef FEATURE_SEARCH_HIGHLIGHT - webkit_web_view_mark_text_matches(vb.gui.webview, vb.state.search_query, false, 0); - webkit_web_view_set_highlight_text_matches(vb.gui.webview, true); + if (!highlight) { + /* highlight matches if the search is started new or continued + * after switch to normal mode which calls this function with + * VB_SEARCH_OFF */ + webkit_web_view_mark_text_matches(vb.gui.webview, query, false, 0); + webkit_web_view_set_highlight_text_matches(vb.gui.webview, true); + + /* mark the search as active */ + highlight = true; + } #endif + /* make sure we have a count greater than 0 */ vb.state.count = vb.state.count ? vb.state.count : 1; do { - if (!webkit_web_view_search_text(vb.gui.webview, vb.state.search_query, false, forward, true)) { + if (!webkit_web_view_search_text(vb.gui.webview, query, false, forward, true)) { break; } } while (--vb.state.count); diff --git a/src/main.h b/src/main.h index 9aa74da..15fc24a 100644 --- a/src/main.h +++ b/src/main.h @@ -267,8 +267,6 @@ typedef struct { StatusType status_type; MessageType input_type; gboolean is_inspecting; - SearchDirection search_dir; - char *search_query; GList *downloads; } State;