Changed the bookmark completion (#27).
authorDaniel Carl <danielcarl@gmx.de>
Tue, 28 May 2013 19:31:45 +0000 (21:31 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Tue, 28 May 2013 19:31:45 +0000 (21:31 +0200)
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

index 09ba6f4..0197c20 100644 (file)
@@ -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;
 }