From e79193760802414c915a9f57d369ac109129af12 Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Tue, 28 May 2013 21:31:45 +0200 Subject: [PATCH] Changed the bookmark completion (#27). If completion is started without any tags, all bookmarks without tags are completed. If tags are given, only those bookmarks are matched that have all given tags set. --- src/bookmark.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/bookmark.c b/src/bookmark.c index 09ba6f4..0197c20 100644 --- a/src/bookmark.c +++ b/src/bookmark.c @@ -62,25 +62,30 @@ GList *bookmark_get_by_tags(const char *tags) char **parts; unsigned int len; + src = load(vb.files[FILES_BOOKMARK]); if (!tags || *tags == '\0') { - return NULL; - } - - src = load(vb.files[FILES_BOOKMARK]); - parts = g_strsplit(tags, " ", 0); - len = g_strv_length(parts); - - for (GList *l = src; l; l = l->next) { - Bookmark *bm = (Bookmark*)l->data; - if (bm->tags - && contains_all_tags(bm->tags, g_strv_length(bm->tags), parts, len) - ) { - res = g_list_prepend(res, g_strdup(bm->uri)); + for (GList *l = src; l; l = l->next) { + Bookmark *bm = (Bookmark*)l->data; + if (!bm->tags) { + res = g_list_prepend(res, g_strdup(bm->uri)); + } + } + } else { + parts = g_strsplit(tags, " ", 0); + len = g_strv_length(parts); + + for (GList *l = src; l; l = l->next) { + Bookmark *bm = (Bookmark*)l->data; + if (bm->tags + && contains_all_tags(bm->tags, g_strv_length(bm->tags), parts, len) + ) { + res = g_list_prepend(res, g_strdup(bm->uri)); + } } + g_strfreev(parts); } g_list_free_full(src, (GDestroyNotify)free_bookmark); - g_strfreev(parts); return res; } -- 2.20.1