From 0a9c64352001ea9c094f275c52d220d768ab73ac Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Tue, 17 Sep 2019 23:06:06 +0100 Subject: fix core find in page behaviour when case sensitivity is toggled --- content/handlers/html/html_interaction.c | 22 ++++--- content/handlers/html/search.c | 102 +++++++++++++++++-------------- content/handlers/html/search.h | 5 -- 3 files changed, 68 insertions(+), 61 deletions(-) diff --git a/content/handlers/html/html_interaction.c b/content/handlers/html/html_interaction.c index 5f165e362..d31ad1d06 100644 --- a/content/handlers/html/html_interaction.c +++ b/content/handlers/html/html_interaction.c @@ -1165,21 +1165,25 @@ bool html_keypress(struct content *c, uint32_t key) /** * Handle search. * - * \param c content of type HTML - * \param context front end private data - * \param flags search flags - * \param string search string + * \param c content of type HTML + * \param context front end private data + * \param flags search flags + * \param string search string */ -void html_search(struct content *c, void *context, - search_flags_t flags, const char *string) +void +html_search(struct content *c, + void *context, + search_flags_t flags, + const char *string) { html_content *html = (html_content *)c; assert(c != NULL); - if (string != NULL && html->search_string != NULL && - strcmp(string, html->search_string) == 0 && - html->search != NULL) { + if ((string != NULL) && + (html->search_string != NULL) && + (strcmp(string, html->search_string) == 0) && + (html->search != NULL)) { /* Continue prev. search */ search_step(html->search, flags, string); diff --git a/content/handlers/html/search.c b/content/handlers/html/search.c index e26510e6e..3599951a7 100644 --- a/content/handlers/html/search.c +++ b/content/handlers/html/search.c @@ -421,6 +421,49 @@ static bool find_occurrences_text(const char *pattern, int p_len, } +/** + * Specifies whether all matches or just the current match should + * be highlighted in the search text. + */ +static void search_show_all(bool all, struct search_context *context) +{ + struct list_entry *a; + + for (a = context->found->next; a; a = a->next) { + bool add = true; + if (!all && a != context->current) { + add = false; + if (a->sel) { + selection_clear(a->sel, true); + selection_destroy(a->sel); + a->sel = NULL; + } + } + if (add && !a->sel) { + + if (context->is_html == true) { + html_content *html = (html_content *)context->c; + a->sel = selection_create(context->c, true); + if (!a->sel) + continue; + + selection_init(a->sel, html->layout, + &html->len_ctx); + } else { + a->sel = selection_create(context->c, false); + if (!a->sel) + continue; + + selection_init(a->sel, NULL, NULL); + } + + selection_set_start(a->sel, a->start_idx); + selection_set_end(a->sel, a->end_idx); + } + } +} + + /** * Search for a string in the box tree * @@ -429,8 +472,11 @@ static bool find_occurrences_text(const char *pattern, int p_len, * \param context The search context to add the entry to. * \param flags flags to control the search. */ -static void search_text(const char *string, int string_len, - struct search_context *context, search_flags_t flags) +static void +search_text(const char *string, + int string_len, + struct search_context *context, + search_flags_t flags) { struct rect bounds; struct box *box = NULL; @@ -456,7 +502,8 @@ static void search_text(const char *string, int string_len, /* check if we need to start a new search or continue an old one */ - if (context->newsearch) { + if ((context->newsearch) || + (context->prev_case_sens != case_sensitive)) { bool res; if (context->string != NULL) @@ -543,16 +590,15 @@ static void search_text(const char *string, int string_len, /* Exported function documented in search.h */ -void search_step(struct search_context *context, search_flags_t flags, - const char *string) +void +search_step(struct search_context *context, + search_flags_t flags, + const char *string) { int string_len; int i = 0; - if (context == NULL) { - guit->misc->warning("SearchError", 0); - return; - } + assert(context != NULL); guit->search->add_recent(string, context->gui_p); @@ -598,44 +644,6 @@ bool search_term_highlighted(struct content *c, } -/* Exported function documented in search.h */ -void search_show_all(bool all, struct search_context *context) -{ - struct list_entry *a; - - for (a = context->found->next; a; a = a->next) { - bool add = true; - if (!all && a != context->current) { - add = false; - if (a->sel) { - selection_clear(a->sel, true); - selection_destroy(a->sel); - a->sel = NULL; - } - } - if (add && !a->sel) { - - if (context->is_html == true) { - html_content *html = (html_content *)context->c; - a->sel = selection_create(context->c, true); - if (!a->sel) - continue; - - selection_init(a->sel, html->layout, - &html->len_ctx); - } else { - a->sel = selection_create(context->c, false); - if (!a->sel) - continue; - - selection_init(a->sel, NULL, NULL); - } - - selection_set_start(a->sel, a->start_idx); - selection_set_end(a->sel, a->end_idx); - } - } -} /* Exported function documented in search.h */ diff --git a/content/handlers/html/search.h b/content/handlers/html/search.h index 5c9408e3e..dfb1afc64 100644 --- a/content/handlers/html/search.h +++ b/content/handlers/html/search.h @@ -60,11 +60,6 @@ void search_destroy_context(struct search_context *context); void search_step(struct search_context *context, search_flags_t flags, const char * string); -/** - * Specifies whether all matches or just the current match should - * be highlighted in the search text. - */ -void search_show_all(bool all, struct search_context *context); /** * Determines whether any portion of the given text box should be -- cgit v1.2.3