[gnome-builder] search-entry: add support for escape sequences
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] search-entry: add support for escape sequences
- Date: Sun, 3 Apr 2016 03:01:27 +0000 (UTC)
commit 7201bbe728ce114a1ad31024900e7c284cdab192
Author: Fangwen Yu <yynyygy gmail com>
Date: Sat Mar 19 20:10:45 2016 +0800
search-entry: add support for escape sequences
If regex search option is not enabled, call
gtk_source_utils_unescape_search_text() on the search entry text,
to unescape the following sequences of characters: \n, \r, \t and
\. This allows the users to easily write those characters in the
search entry.
https://bugzilla.gnome.org/show_bug.cgi?id=764178
libide/editor/ide-editor-frame-actions.c | 24 +++++++++++++++-------
libide/editor/ide-editor-frame.c | 32 +++++++++++++++++++++++++++--
libide/ide-source-view.c | 7 +++--
3 files changed, 49 insertions(+), 14 deletions(-)
---
diff --git a/libide/editor/ide-editor-frame-actions.c b/libide/editor/ide-editor-frame-actions.c
index 53e8009..6f37084 100644
--- a/libide/editor/ide-editor-frame-actions.c
+++ b/libide/editor/ide-editor-frame-actions.c
@@ -28,8 +28,6 @@ ide_editor_frame_actions_find (GSimpleAction *action,
{
IdeEditorFrame *self = user_data;
GtkTextBuffer *buffer;
- GtkTextIter start_sel;
- GtkTextIter end_sel;
GtkDirectionType search_direction;
g_assert (IDE_IS_EDITOR_FRAME (self));
@@ -48,15 +46,25 @@ ide_editor_frame_actions_find (GSimpleAction *action,
if (gtk_text_buffer_get_has_selection (buffer))
{
+ GtkTextIter start_sel;
+ GtkTextIter end_sel;
+ g_autofree gchar *selected_text = NULL;
+ g_autofree gchar *escaped_selected_text = NULL;
+ GtkSourceSearchContext *search_context;
+ GtkSourceSearchSettings *search_settings;
+
gtk_text_buffer_get_selection_bounds (buffer, &start_sel, &end_sel);
+ selected_text = gtk_text_buffer_get_text (buffer, &start_sel, &end_sel, FALSE);
+
+ search_context = ide_source_view_get_search_context (self->source_view);
+ search_settings = gtk_source_search_context_get_settings (search_context);
- if (gtk_text_iter_get_line (&start_sel) == gtk_text_iter_get_line (&end_sel))
- {
- g_autofree gchar *selected_text;
+ if (gtk_source_search_settings_get_regex_enabled (search_settings))
+ escaped_selected_text = g_regex_escape_string (selected_text, -1);
+ else
+ escaped_selected_text = gtk_source_utils_escape_search_text (selected_text);
- selected_text = gtk_text_buffer_get_text (buffer, &start_sel, &end_sel, FALSE);
- gtk_entry_set_text (GTK_ENTRY (self->search_entry), selected_text);
- }
+ gtk_entry_set_text (GTK_ENTRY (self->search_entry), escaped_selected_text);
}
else if (self->previous_search_string != NULL)
{
diff --git a/libide/editor/ide-editor-frame.c b/libide/editor/ide-editor-frame.c
index 602ab68..45c3c44 100644
--- a/libide/editor/ide-editor-frame.c
+++ b/libide/editor/ide-editor-frame.c
@@ -309,13 +309,39 @@ search_text_transform_to (GBinding *binding,
GValue *to_value,
gpointer user_data)
{
+ IdeEditorFrame *self = user_data;
+
+ g_assert (IDE_IS_EDITOR_FRAME (self));
g_assert (from_value != NULL);
g_assert (to_value != NULL);
if (g_value_get_string (from_value) == NULL)
- g_value_set_string (to_value, "");
+ {
+ g_value_set_string (to_value, "");
+ }
else
- g_value_copy (from_value, to_value);
+ {
+ const gchar *entry_text = g_value_get_string (from_value);
+ GtkSourceSearchContext *search_context;
+ GtkSourceSearchSettings *search_settings;
+
+ search_context = ide_source_view_get_search_context (self->source_view);
+ search_settings = gtk_source_search_context_get_settings (search_context);
+
+ if (gtk_source_search_settings_get_regex_enabled (search_settings))
+ {
+ g_value_set_string (to_value, entry_text);
+ }
+ else
+ {
+ gchar *unescaped_entry_text;
+
+ unescaped_entry_text = gtk_source_utils_unescape_search_text (entry_text);
+ g_value_set_string (to_value, unescaped_entry_text);
+
+ g_free (unescaped_entry_text);
+ }
+ }
return TRUE;
}
@@ -374,7 +400,7 @@ ide_editor_frame_set_document (IdeEditorFrame *self,
g_object_bind_property_full (self->search_entry, "text", search_settings, "search-text",
(G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL),
search_text_transform_to, search_text_transform_from,
- NULL, NULL);
+ self, NULL);
g_signal_connect_object (search_context,
"notify::occurrences-count",
G_CALLBACK (ide_editor_frame_on_search_occurrences_notify),
diff --git a/libide/ide-source-view.c b/libide/ide-source-view.c
index 2d4ba75..a5a411e 100644
--- a/libide/ide-source-view.c
+++ b/libide/ide-source-view.c
@@ -4394,10 +4394,11 @@ add_match (GtkTextView *text_view,
}
/*
- * TODO: Complex matches.
+ * TODO: Add support for multi-line matches. When @begin and @end are not
+ * on the same line, we need to add the match region to @region so
+ * ide_source_view_draw_search_bubbles() can draw search bubbles
+ * around it.
*/
-
- g_warning ("Need to support complex matches (multi-line)");
}
static guint
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]