[gnome-text-editor] document: short-circuit insert-text/delete-range during load



commit a5a2a738662aeab07fc6fabe485902605bc92ae7
Author: Christian Hergert <chergert redhat com>
Date:   Mon Aug 1 12:27:44 2022 -0700

    document: short-circuit insert-text/delete-range during load
    
    We won't be able to keep things like our spellcheck datastructure up to
    date, but it's easy enough to validate that *after* loading the document.
    
    This can get bad when inserting a file full of relatively small multi-byte
    "invalid-character" unichars one at a time.
    
    Related #444

 src/editor-document.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
---
diff --git a/src/editor-document.c b/src/editor-document.c
index 5abafd1..8daead0 100644
--- a/src/editor-document.c
+++ b/src/editor-document.c
@@ -288,6 +288,8 @@ editor_document_load_notify_completed_cb (EditorDocument *self,
 
   self->loading = FALSE;
 
+  editor_text_buffer_spell_adapter_invalidate_all (self->spell_adapter);
+
   if (!g_task_had_error (task))
     editor_document_track_error (self, NULL);
 
@@ -382,6 +384,15 @@ editor_document_insert_text (GtkTextBuffer *buffer,
   g_assert (pos != NULL);
   g_assert (new_text != NULL);
 
+  /* Short-circuit during loading, we'll handle the followup
+   * actions after loading has completed.
+   */
+  if (self->loading)
+    {
+      GTK_TEXT_BUFFER_CLASS (editor_document_parent_class)->insert_text (buffer, pos, new_text, 
new_text_length);
+      return;
+    }
+
   line = gtk_text_iter_get_line (pos);
   offset = gtk_text_iter_get_offset (pos);
   length = g_utf8_strlen (new_text, new_text_length);
@@ -415,6 +426,16 @@ editor_document_delete_range (GtkTextBuffer *buffer,
   g_assert (end != NULL);
   g_assert (gtk_text_iter_compare (start, end) <= 0);
 
+  /* Unlikely, but short circuit during loading incase something
+   * beneath us has to delete/replace as part of resolving invalid
+   * characters.
+   */
+  if (self->loading)
+    {
+      GTK_TEXT_BUFFER_CLASS (editor_document_parent_class)->delete_range (buffer, start, end);
+      return;
+    }
+
   offset = gtk_text_iter_get_offset (start);
   length = gtk_text_iter_get_offset (end) - offset;
 


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