[gnome-builder] quickhighlight: allow specifying min char length
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] quickhighlight: allow specifying min char length
- Date: Mon, 20 Dec 2021 23:55:51 +0000 (UTC)
commit 59f61be468a86e470c05b31366df82d4cd842240
Author: Bryan Paget <bryanpaget pm me>
Date: Mon May 3 22:21:03 2021 -0400
quickhighlight: allow specifying min char length
Allows specifying the minimum number of characters in a selection before
the quick-highlight plugin will highlight matches.
data/gsettings/org.gnome.builder.editor.gschema.xml | 6 ++++++
.../gbp-quick-highlight-editor-page-addin.c | 18 +++++++++++++++++-
.../quick-highlight/gbp-quick-highlight-preferences.c | 17 +++++++++++++++++
3 files changed, 40 insertions(+), 1 deletion(-)
---
diff --git a/data/gsettings/org.gnome.builder.editor.gschema.xml
b/data/gsettings/org.gnome.builder.editor.gschema.xml
index facc9c46a..71a700437 100644
--- a/data/gsettings/org.gnome.builder.editor.gschema.xml
+++ b/data/gsettings/org.gnome.builder.editor.gschema.xml
@@ -128,5 +128,11 @@
<summary>Interactive Completion</summary>
<description>If enabled, Builder will automatically display completion proposals as you
type.</description>
</key>
+ <key name="min-char-selected" type="i">
+ <default>1</default>
+ <range min="1" max="32"/>
+ <summary>Minimum characters for matching selection.</summary>
+ <description>Specify the mininum number of characters for selection matching.</description>
+ </key>
</schema>
</schemalist>
diff --git a/src/plugins/quick-highlight/gbp-quick-highlight-editor-page-addin.c
b/src/plugins/quick-highlight/gbp-quick-highlight-editor-page-addin.c
index b6925e1f8..bb5f0882d 100644
--- a/src/plugins/quick-highlight/gbp-quick-highlight-editor-page-addin.c
+++ b/src/plugins/quick-highlight/gbp-quick-highlight-editor-page-addin.c
@@ -31,6 +31,8 @@ struct _GbpQuickHighlightEditorPageAddin
{
GObject parent_instance;
+ GSettings *settings;
+
IdeEditorPage *view;
DzlSignalGroup *buffer_signals;
@@ -51,6 +53,8 @@ do_delayed_quick_highlight (GbpQuickHighlightEditorPageAddin *self)
IdeBuffer *buffer;
GtkTextIter begin;
GtkTextIter end;
+ int selection_length;
+ int min_length;
g_assert (GBP_IS_QUICK_HIGHLIGHT_EDITOR_PAGE_ADDIN (self));
g_assert (self->view != NULL);
@@ -58,7 +62,7 @@ do_delayed_quick_highlight (GbpQuickHighlightEditorPageAddin *self)
self->queued_match_source = 0;
/*
- * Get the curretn selection, if any. Short circuit if we find a situation
+ * Get the current selection, if any. Short circuit if we find a situation
* that should have caused us to cancel the current quick-highlight.
*/
buffer = ide_editor_page_get_buffer (self->view);
@@ -70,6 +74,14 @@ do_delayed_quick_highlight (GbpQuickHighlightEditorPageAddin *self)
return G_SOURCE_REMOVE;
}
+ min_length = g_settings_get_int (self->settings, "min-char-selected");
+ selection_length = gtk_text_iter_get_offset (&end) - gtk_text_iter_get_offset (&begin);
+ if (selection_length < min_length)
+ {
+ g_clear_object (&self->search_context);
+ return G_SOURCE_REMOVE;
+ }
+
/*
* If the current selection goes across a line, then ignore trying to match
* anything similar as it's unlikely to be what the user wants.
@@ -203,6 +215,8 @@ gbp_quick_highlight_editor_page_addin_load (IdeEditorPageAddin *addin,
self->view = view;
+ self->settings = g_settings_new ("org.gnome.builder.editor");
+
self->buffer_signals = dzl_signal_group_new (IDE_TYPE_BUFFER);
dzl_signal_group_connect_swapped (self->buffer_signals,
@@ -249,6 +263,8 @@ gbp_quick_highlight_editor_page_addin_unload (IdeEditorPageAddin *addin,
dzl_signal_group_set_target (self->search_signals, NULL);
g_clear_object (&self->search_signals);
+ g_clear_object (&self->settings);
+
self->view = NULL;
}
diff --git a/src/plugins/quick-highlight/gbp-quick-highlight-preferences.c
b/src/plugins/quick-highlight/gbp-quick-highlight-preferences.c
index f55099c31..ade13cc41 100644
--- a/src/plugins/quick-highlight/gbp-quick-highlight-preferences.c
+++ b/src/plugins/quick-highlight/gbp-quick-highlight-preferences.c
@@ -28,6 +28,7 @@ struct _GbpQuickHighlightPreferences
{
GObject parent_instance;
guint enable_switch;
+ guint min_char_spin_button;
};
static void
@@ -52,6 +53,19 @@ gbp_quick_highlight_preferences_load (IdePreferencesAddin *addin,
/* Translators: the following are keywords used for searching to locate this
preference */
_("quick highlight words matching current selection"),
10);
+
+ self->min_char_spin_button =
+ dzl_preferences_add_spin_button (preferences,
+ "editor",
+ "highlight",
+ "org.gnome.builder.editor",
+ "min-char-selected",
+ "/org/gnome/builder/editor/",
+ _("Minimum length for highlight"),
+ _("Highlight words matching at least this number of characters"),
+ /* Translators: the following are keywords used for searching to locate
this preference */
+ _("quick highlight words matching current selection minimum length"),
+ 10);
}
static void
@@ -65,6 +79,9 @@ gbp_quick_highlight_preferences_unload (IdePreferencesAddin *addin,
dzl_preferences_remove_id (preferences, self->enable_switch);
self->enable_switch = 0;
+
+ dzl_preferences_remove_id (preferences, self->min_char_spin_button);
+ self->min_char_spin_button = 0;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]