summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCristian Margineanu <margineanucristi96@gmail.com>2017-05-13 14:20:30 +0300
committerMichael Catanzaro <mcatanzaro@igalia.com>2017-05-20 09:24:27 -0500
commit03cc1be2f472c092d66f63689ddf81ba74b91906 (patch)
tree35c5d4a4c6ab338bd6a340100894742e86076fb9
parente16328dad2397775d3cc57f8e04e39c77891b498 (diff)
downloadepiphany-03cc1be2f472c092d66f63689ddf81ba74b91906.tar.gz
completion-model: match tags against text in address bar
https://bugzilla.gnome.org/show_bug.cgi?id=781746
-rw-r--r--src/ephy-completion-model.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/src/ephy-completion-model.c b/src/ephy-completion-model.c
index f22a64544..e1faae148 100644
--- a/src/ephy-completion-model.c
+++ b/src/ephy-completion-model.c
@@ -291,10 +291,30 @@ replace_rows_in_model (EphyCompletionModel *model, GSList *new_rows)
static gboolean
should_add_bookmark_to_model (EphyCompletionModel *model,
const char *search_string,
- const char *title,
- const char *location)
+ EphyBookmark *bookmark)
{
gboolean ret = TRUE;
+ GSequence *tags;
+ GSequenceIter *tag_iter;
+ const char *url;
+ const char *title;
+ char *tag_string = NULL;
+ char **tag_array;
+ int i;
+
+ title = ephy_bookmark_get_title (bookmark);
+ url = ephy_bookmark_get_url (bookmark);
+ tags = ephy_bookmark_get_tags (bookmark);
+
+ tag_array = g_malloc0 ((g_sequence_get_length (tags) + 1) * sizeof (char *));
+
+ for (i = 0, tag_iter = g_sequence_get_begin_iter (tags);
+ !g_sequence_iter_is_end (tag_iter);
+ i++, tag_iter = g_sequence_iter_next (tag_iter)) {
+ tag_array[i] = g_sequence_get (tag_iter);
+ }
+
+ tag_string = g_strjoinv (" ", tag_array);
if (model->search_terms) {
GSList *iter;
@@ -302,14 +322,19 @@ should_add_bookmark_to_model (EphyCompletionModel *model,
for (iter = model->search_terms; iter != NULL; iter = iter->next) {
current = (GRegex *)iter->data;
+
if ((!g_regex_match (current, title ? title : "", G_REGEX_MATCH_NOTEMPTY, NULL)) &&
- (!g_regex_match (current, location ? location : "", G_REGEX_MATCH_NOTEMPTY, NULL))) {
+ (!g_regex_match (current, url ? url : "", G_REGEX_MATCH_NOTEMPTY, NULL)) &&
+ (!g_regex_match (current, tag_string ? tag_string : "", G_REGEX_MATCH_NOTEMPTY, NULL))) {
ret = FALSE;
break;
}
}
}
+ g_free (tag_array);
+ g_free (tag_string);
+
return ret;
}
@@ -426,12 +451,11 @@ query_completed_cb (EphyHistoryService *service,
bookmark = g_sequence_get (iter);
- url = ephy_bookmark_get_url (bookmark);
- title = ephy_bookmark_get_title (bookmark);
-
- if (should_add_bookmark_to_model (model, user_data->search_string,
- title, url))
+ if (should_add_bookmark_to_model (model, user_data->search_string, bookmark)) {
+ url = ephy_bookmark_get_url (bookmark);
+ title = ephy_bookmark_get_title (bookmark);
list = add_to_potential_rows (list, title, url, NULL, 0, TRUE, FALSE);
+ }
}
/* History */