[gnome-builder] source-view: avoid modifying opposite selections
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] source-view: avoid modifying opposite selections
- Date: Mon, 26 Mar 2018 08:04:55 +0000 (UTC)
commit d2a3e61261db6ab65c0e0d0581152156bf5898d9
Author: Christian Hergert <chergert redhat com>
Date: Mon Mar 26 00:04:53 2018 -0700
source-view: avoid modifying opposite selections
In case we have an equal selection with the direction reversed, ignore that
since its essentially the same selection we expect. It allows us to avoid
extraneous events cascaded by selection changes.
src/libide/sourceview/ide-source-view.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
---
diff --git a/src/libide/sourceview/ide-source-view.c b/src/libide/sourceview/ide-source-view.c
index 551bff80e..fcaf101e2 100644
--- a/src/libide/sourceview/ide-source-view.c
+++ b/src/libide/sourceview/ide-source-view.c
@@ -3547,6 +3547,21 @@ wrapped:
}
}
+static gboolean
+is_same_range (GtkTextIter *new_start,
+ GtkTextIter *old_start,
+ GtkTextIter *new_sel,
+ GtkTextIter *old_sel)
+{
+ if (gtk_text_iter_equal (new_start, old_start))
+ return gtk_text_iter_equal (old_sel, new_sel);
+
+ if (gtk_text_iter_equal (new_start, old_sel))
+ return gtk_text_iter_equal (old_start, new_sel);
+
+ return FALSE;
+}
+
static void
ide_source_view_real_restore_insert_mark_full (IdeSourceView *self,
gboolean move_mark)
@@ -3555,6 +3570,8 @@ ide_source_view_real_restore_insert_mark_full (IdeSourceView *self,
GtkTextBuffer *buffer;
GtkTextIter iter;
GtkTextIter selection;
+ GtkTextIter old_iter;
+ GtkTextIter old_selection;
g_assert (IDE_IS_SOURCE_VIEW (self));
@@ -3576,7 +3593,10 @@ ide_source_view_real_restore_insert_mark_full (IdeSourceView *self,
priv->saved_selection_line_column,
&selection);
- gtk_text_buffer_select_range (buffer, &iter, &selection);
+ gtk_text_buffer_get_selection_bounds (buffer, &old_iter, &old_selection);
+
+ if (!is_same_range (&iter, &old_iter, &selection, &old_selection))
+ gtk_text_buffer_select_range (buffer, &iter, &selection);
if (move_mark)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]