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



commit 20ad32109c724289891534528c7f50298c727798
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 8bb16e74e..25f0f65d2 100644
--- a/src/libide/sourceview/ide-source-view.c
+++ b/src/libide/sourceview/ide-source-view.c
@@ -5478,6 +5478,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)
 {
@@ -5735,6 +5752,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;
 
@@ -5761,6 +5779,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]