[gnome-builder] snippets: sort matching snippets by length
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] snippets: sort matching snippets by length
- Date: Wed, 13 Jun 2018 00:14:54 +0000 (UTC)
commit 4e1874f3c0dc1c3c46f1e8057a6985009f503f21
Author: Christian Hergert <chergert redhat com>
Date: Tue Jun 12 17:13:22 2018 -0700
snippets: sort matching snippets by length
This makes things more predictable as it used to be before porting this to
the new completion engine.
src/plugins/snippets/ide-snippet-model.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
---
diff --git a/src/plugins/snippets/ide-snippet-model.c b/src/plugins/snippets/ide-snippet-model.c
index a02907d5d..015564925 100644
--- a/src/plugins/snippets/ide-snippet-model.c
+++ b/src/plugins/snippets/ide-snippet-model.c
@@ -75,6 +75,20 @@ ide_snippet_model_new (IdeSnippetStorage *storage)
return self;
}
+static gint
+compare_items (gconstpointer a,
+ gconstpointer b)
+{
+ const IdeSnippetInfo *ai = *(const IdeSnippetInfo **)a;
+ const IdeSnippetInfo *bi = *(const IdeSnippetInfo **)b;
+
+ /* At this point, everything matches prefix, so we just want
+ * to use the shorter string.
+ */
+
+ return (gint)strlen (ai->name) - (gint)strlen (bi->name);
+}
+
static void
foreach_cb (IdeSnippetStorage *storage,
const IdeSnippetInfo *info,
@@ -101,6 +115,8 @@ ide_snippet_model_update (IdeSnippetModel *self)
ide_snippet_storage_query (self->storage, self->language, self->prefix, foreach_cb, self);
+ g_ptr_array_sort (self->items, compare_items);
+
if (old_len || self->items->len)
g_list_model_items_changed (G_LIST_MODEL (self), 0, old_len, self->items->len);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]