[gnome-builder] source-view: disable snippets when performing undo



commit 731baa2967de77cd88f946a9f7d3860501c5edc2
Author: Christian Hergert <chergert redhat com>
Date:   Sat Mar 31 13:16:36 2018 -0700

    source-view: disable snippets when performing undo
    
    Unfortunately, we don't have a great way to deal with buffer changes while
    snippet editing is in play. So we can just disable them when we come
    across an undo request.
    
    The problem at hand is tracking virtual edit-points across buffer changes
    that are outside the snippet driver's control. This sort of "forms editing"
    really needs to be handled as part of a core textview design if we want to
    support this well.

 src/libide/sourceview/ide-source-view.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
---
diff --git a/src/libide/sourceview/ide-source-view.c b/src/libide/sourceview/ide-source-view.c
index fcaf101e2..2270e788a 100644
--- a/src/libide/sourceview/ide-source-view.c
+++ b/src/libide/sourceview/ide-source-view.c
@@ -5501,6 +5501,23 @@ ide_source_view_real_request_documentation (IdeSourceView *self)
   g_signal_emit (self, signals [DOCUMENTATION_REQUESTED], 0, word);
 }
 
+static void
+ide_source_view_real_undo (GtkSourceView *view)
+{
+  IdeSourceView *self = (IdeSourceView *)view;
+
+  g_assert (IDE_IS_SOURCE_VIEW (self));
+
+  /*
+   * Disable things that could confuse undo. For example, we need to bail on
+   * any in-flight snippets because they just can't deal with the buffer
+   * changes correctly given the GtkTextMark vs run-length design.
+   */
+  ide_source_view_clear_snippets (self);
+
+  GTK_SOURCE_VIEW_CLASS (ide_source_view_parent_class)->undo (view);
+}
+
 static void
 ide_source_view_real_reset (IdeSourceView *self)
 {
@@ -5758,6 +5775,7 @@ ide_source_view_class_init (IdeSourceViewClass *klass)
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
   GtkTextViewClass *text_view_class = GTK_TEXT_VIEW_CLASS (klass);
+  GtkSourceViewClass *gsv_class = GTK_SOURCE_VIEW_CLASS (klass);
   GtkBindingSet *binding_set;
   GTypeClass *completion_class;
 
@@ -5784,6 +5802,8 @@ ide_source_view_class_init (IdeSourceViewClass *klass)
   text_view_class->insert_at_cursor = ide_source_view_real_insert_at_cursor;
   text_view_class->populate_popup = ide_source_view_real_populate_popup;
 
+  gsv_class->undo = ide_source_view_real_undo;
+
   klass->add_cursor = ide_source_view_real_add_cursor;
   klass->remove_cursors = ide_source_view_real_remove_cursors;
   klass->append_to_count = ide_source_view_real_append_to_count;


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