b4n left a comment (geany/geany#4481)

The idea of making the search work is neat, however wouldn't it be better to 
have a fuzzier match, potentially even matching the description (so one has 
more results than merely the very name she has to know exactly)?

What about setting a custom match function on the existing `markup` that 
already has it all? it could match the markup itself, but it doesn't seem to be 
a huge issue I don't think.

e.g.
```diff
diff --git a/src/highlighting.c b/src/highlighting.c
index e73cd30fd..ca797a805 100644
--- a/src/highlighting.c
+++ b/src/highlighting.c
@@ -1210,7 +1210,6 @@ enum
 {
        SCHEME_MARKUP,
        SCHEME_FILE,
-       SCHEME_NAME,
        SCHEME_COLUMNS
 };
 
@@ -1277,16 +1276,13 @@ static void add_color_scheme_item(GtkListStore *store,
        name = g_markup_escape_text(name, -1);
        desc = g_markup_escape_text(desc, -1);
        markup = g_strdup_printf("<big><b>%s</b></big>\n%s", name, desc);
+       g_free(name);
+       g_free(desc);
 
        gtk_list_store_append(store, &iter);
-       gtk_list_store_set(store, &iter,
-               SCHEME_MARKUP, markup,
-               SCHEME_FILE, fn,
-               SCHEME_NAME, name,
-               -1);
+       gtk_list_store_set(store, &iter, SCHEME_MARKUP, markup,
+               SCHEME_FILE, fn, -1);
        g_free(markup);
-       g_free(name);
-       g_free(desc);
 
        /* select the current iter if the the color scheme matches, or if it's 
the
         * default (fn == NULL), in case of bad config file.  the default theme 
is
@@ -1349,11 +1345,25 @@ static void on_color_scheme_dialog_response(GtkWidget 
*dialog,
 }
 
 
+static gboolean color_scheme_search_equal_func(GtkTreeModel *model,
+       gint column, const gchar *key, GtkTreeIter *iter, gpointer data)
+{
+       gchar *desc;
+       gboolean match;
+
+       gtk_tree_model_get(model, iter, SCHEME_MARKUP, &desc, -1);
+       match = utils_utf8_substring_match(key, desc);
+       g_free(desc);
+
+       return ! match;
+}
+
+
 void highlighting_show_color_scheme_dialog(void)
 {
        static GtkWidget *dialog = NULL;
        GtkListStore *store = gtk_list_store_new(SCHEME_COLUMNS,
-               G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
+               G_TYPE_STRING, G_TYPE_STRING);
        GtkCellRenderer *text_renderer;
        GtkTreeViewColumn *column;
        GtkTreeSelection *treesel;
@@ -1372,7 +1382,7 @@ void highlighting_show_color_scheme_dialog(void)
        g_object_unref(store);
        gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree), TRUE);
        gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree), FALSE);
-       gtk_tree_view_set_search_column(GTK_TREE_VIEW(tree), SCHEME_NAME);
+       gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(tree), 
color_scheme_search_equal_func, NULL, NULL);
 
        text_renderer = gtk_cell_renderer_text_new();
        g_object_set(text_renderer, "wrap-mode", PANGO_WRAP_WORD, NULL);
```

(over master it'd be merely
```diff
diff --git a/src/highlighting.c b/src/highlighting.c
index 2049325b6..ca797a805 100644
--- a/src/highlighting.c
+++ b/src/highlighting.c
@@ -1345,6 +1345,20 @@ static void on_color_scheme_dialog_response(GtkWidget 
*dialog,
 }
 
 
+static gboolean color_scheme_search_equal_func(GtkTreeModel *model,
+       gint column, const gchar *key, GtkTreeIter *iter, gpointer data)
+{
+       gchar *desc;
+       gboolean match;
+
+       gtk_tree_model_get(model, iter, SCHEME_MARKUP, &desc, -1);
+       match = utils_utf8_substring_match(key, desc);
+       g_free(desc);
+
+       return ! match;
+}
+
+
 void highlighting_show_color_scheme_dialog(void)
 {
        static GtkWidget *dialog = NULL;
@@ -1368,6 +1382,7 @@ void highlighting_show_color_scheme_dialog(void)
        g_object_unref(store);
        gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree), TRUE);
        gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree), FALSE);
+       gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(tree), 
color_scheme_search_equal_func, NULL, NULL);
 
        text_renderer = gtk_cell_renderer_text_new();
        g_object_set(text_renderer, "wrap-mode", PANGO_WRAP_WORD, NULL);
```
)

-- 
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany/pull/4481#issuecomment-3614347372
You are receiving this because you are subscribed to this thread.

Message ID: <geany/geany/pull/4481/[email protected]>

Reply via email to