[gedit/gnome-3-10] ViewFrame: fix search triggering
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/gnome-3-10] ViewFrame: fix search triggering
- Date: Tue, 4 Feb 2014 17:47:09 +0000 (UTC)
commit 6370840ad27fded06d9f2df316fe74e5ec37e0f7
Author: Sébastien Wilmet <swilmet gnome org>
Date: Tue Feb 4 18:30:02 2014 +0100
ViewFrame: fix search triggering
Trigger the search when the search text is new.
When gtk_text_buffer_select_range() is called, the selection in the
search entry is lost. gtk_text_buffer_select_range() is called when the
search is triggered (i.e. when the buffer is searched).
When the search text is the same, no need to trigger the search, and we
can select the text in the search entry, so the user can search for
something else. On the other hand, when the search text is new, we must
trigger the search, and we are not able to (easily) select the text in
the search entry. But it's not a problem, since the search text is new,
so the user doesn't want to search for something completely different,
he just perhaps wants to adjust a little the search text.
gedit/gedit-view-frame.c | 43 ++++++++++++++++++++++++++++++++-----------
1 files changed, 32 insertions(+), 11 deletions(-)
---
diff --git a/gedit/gedit-view-frame.c b/gedit/gedit-view-frame.c
index 4024edb..4ebd324 100644
--- a/gedit/gedit-view-frame.c
+++ b/gedit/gedit-view-frame.c
@@ -1286,17 +1286,38 @@ init_search_entry (GeditViewFrame *frame)
search_text_escaped = gtk_source_utils_escape_search_text (search_text);
}
- g_signal_handler_block (frame->priv->search_entry,
- frame->priv->search_entry_changed_id);
-
- gtk_entry_set_text (GTK_ENTRY (frame->priv->search_entry),
- search_text_escaped);
-
- gtk_editable_select_region (GTK_EDITABLE (frame->priv->search_entry),
- 0, -1);
-
- g_signal_handler_unblock (frame->priv->search_entry,
- frame->priv->search_entry_changed_id);
+ if (g_strcmp0 (search_text_escaped, frame->priv->search_text) == 0)
+ {
+ /* The search text is the same, no need to
+ * trigger the search again. We prefer to select
+ * the text in the search entry, so the user can
+ * easily search something else.
+ */
+ g_signal_handler_block (frame->priv->search_entry,
+ frame->priv->search_entry_changed_id);
+
+ gtk_entry_set_text (GTK_ENTRY (frame->priv->search_entry),
+ search_text_escaped);
+
+ gtk_editable_select_region (GTK_EDITABLE (frame->priv->search_entry),
+ 0, -1);
+
+ g_signal_handler_unblock (frame->priv->search_entry,
+ frame->priv->search_entry_changed_id);
+ }
+ else
+ {
+ /* search_text_escaped is new, so we trigger the
+ * search (by not blocking the signal), and we
+ * don't select the text in the search entry
+ * because the user wants to search for
+ * search_text_escaped, not for something else.
+ */
+ gtk_entry_set_text (GTK_ENTRY (frame->priv->search_entry),
+ search_text_escaped);
+
+ gtk_editable_set_position (GTK_EDITABLE (frame->priv->search_entry), -1);
+ }
g_free (search_text_escaped);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]