[libadwaita/wip/sophie-h/pref-row-markup: 4/8] Strip markup in seach compare




commit c244a7e29f687691fc0ad1d5f3c58dd6d1de407b
Author: Sophie Herold <sophie hemio de>
Date:   Tue Feb 15 23:07:42 2022 +0100

    Strip markup in seach compare

 src/adw-preferences-row.c    |  2 +-
 src/adw-preferences-window.c | 43 +++++++++++++++++++++++++++++--------------
 2 files changed, 30 insertions(+), 15 deletions(-)
---
diff --git a/src/adw-preferences-row.c b/src/adw-preferences-row.c
index 9e567f8c..f1573e1d 100644
--- a/src/adw-preferences-row.c
+++ b/src/adw-preferences-row.c
@@ -163,7 +163,7 @@ adw_preferences_row_class_init (AdwPreferencesRowClass *klass)
                           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
 
   /**
-   * AdwPreferencesRow:use-markup (attributes org.gtk.Property.get=adw_preferences_row_get_use_markup 
org.gtk.Property.set=adw_preferences_row_set_use_markup)
+   * AdwPreferencesRow:use-markup: (attributes org.gtk.Property.get=adw_preferences_row_get_use_markup 
org.gtk.Property.set=adw_preferences_row_set_use_markup)
    *
    * Whether to use markup syntax for all elements.
    *
diff --git a/src/adw-preferences-window.c b/src/adw-preferences-window.c
index 40c1b658..1d15074b 100644
--- a/src/adw-preferences-window.c
+++ b/src/adw-preferences-window.c
@@ -129,6 +129,33 @@ strip_mnemonic (const char *src)
   return new_str;
 }
 
+static char *
+make_comparable (const char        *src,
+                 AdwPreferencesRow *row,
+                 gboolean          allow_underline)
+{
+  char* plaintext = g_utf8_casefold (src, -1);
+  GError *error = NULL;
+
+  if (adw_preferences_row_get_use_markup (row)) {
+    pango_parse_markup (
+      plaintext,
+      -1,
+      0,
+      NULL,
+      &plaintext,
+      NULL,
+      &error
+    );
+  }
+
+  if (adw_preferences_row_get_use_underline (row) && allow_underline) {
+    plaintext = strip_mnemonic (plaintext);
+  }
+
+  return plaintext;
+}
+
 static gboolean
 filter_search_results (AdwPreferencesRow    *row,
                        AdwPreferencesWindow *self)
@@ -140,24 +167,12 @@ filter_search_results (AdwPreferencesRow    *row,
   g_assert (ADW_IS_PREFERENCES_ROW (row));
 
   terms = g_utf8_casefold (gtk_editable_get_text (GTK_EDITABLE (priv->search_entry)), -1);
-  title = g_utf8_casefold (adw_preferences_row_get_title (row), -1);
-
-  if (adw_preferences_row_get_use_underline (ADW_PREFERENCES_ROW (row))) {
-    char *stripped_title = strip_mnemonic (title);
-
-    if (stripped_title) {
-      g_free (title);
-
-      title = stripped_title;
-    }
-  }
-
-  // TODO: Looks like a bug, that markup is not removed here?
+  title = make_comparable (adw_preferences_row_get_title (row), row, TRUE);
 
   if (!!strstr (title, terms)) {
     result = TRUE;
   } else if (ADW_IS_ACTION_ROW (row)) {
-    char *subtitle = g_utf8_casefold (adw_action_row_get_subtitle (ADW_ACTION_ROW (row)), -1);
+    char *subtitle = make_comparable (adw_action_row_get_subtitle (ADW_ACTION_ROW(row)), row, FALSE);
 
     if (!!strstr (subtitle, terms))
       result = TRUE;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]