From: Daniel Carl <danielcarl@gmx.de>
Date: Tue, 28 May 2013 19:31:45 +0000 (+0200)
Subject: Changed the bookmark completion (#27).
X-Git-Url: https://git.owens.tech/assets/112-editable-focus.html/assets/112-editable-focus.html/git?a=commitdiff_plain;h=e79193760802414c915a9f57d369ac109129af12;p=vimb.git

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.
---

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;
 }