[gnome-text-editor] document: delay spellcheck setting while loading



commit a4677214d10392cf0cab298453109db9a545bbe3
Author: Christian Hergert <chergert redhat com>
Date:   Thu Aug 5 12:42:59 2021 -0700

    document: delay spellcheck setting while loading
    
    We don't want to apply this mid-load so delay everything until after the
    loading process and silently drop changes while loading.
    
    Improves the situation with #132 a bit more.

 src/editor-document.c | 35 ++++++++++++++++++++++++++---------
 1 file changed, 26 insertions(+), 9 deletions(-)
---
diff --git a/src/editor-document.c b/src/editor-document.c
index c9d8668..19e9957 100644
--- a/src/editor-document.c
+++ b/src/editor-document.c
@@ -78,7 +78,6 @@ typedef struct
   gint64           modified_at;
   guint            n_active;
   guint            highlight_syntax : 1;
-  guint            check_spelling : 1;
   guint            has_draft : 1;
   guint            has_file : 1;
 } Load;
@@ -368,6 +367,24 @@ on_cursor_moved_cb (EditorDocument *self)
 
 }
 
+static gboolean
+apply_spellcheck_mapping (GValue   *value,
+                          GVariant *variant,
+                          gpointer  user_data)
+{
+  EditorDocument *self = user_data;
+
+  g_assert (EDITOR_IS_DOCUMENT (self));
+
+  /* Ignore while loading */
+  if (self->loading)
+    g_value_set_boolean (value, FALSE);
+  else
+    g_value_set_boolean (value, g_variant_get_boolean (variant));
+
+  return TRUE;
+}
+
 static void
 editor_document_constructed (GObject *object)
 {
@@ -380,9 +397,10 @@ editor_document_constructed (GObject *object)
 
   self->spell_adapter = editor_text_buffer_spell_adapter_new (GTK_TEXT_BUFFER (self),
                                                               self->spell_checker);
-  g_settings_bind (shared_settings, "spellcheck",
-                   self->spell_adapter, "enabled",
-                   G_SETTINGS_BIND_GET);
+  g_settings_bind_with_mapping (shared_settings, "spellcheck",
+                                self->spell_adapter, "enabled",
+                                G_SETTINGS_BIND_GET,
+                                apply_spellcheck_mapping, NULL, self, NULL);
 
   self->line_spacing_tag = gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (self),
                                                        NULL,
@@ -1129,7 +1147,8 @@ editor_document_query_info_cb (GObject      *object,
   editor_buffer_monitor_reset (self->monitor);
 
   gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (self), load->highlight_syntax);
-  editor_text_buffer_spell_adapter_set_enabled (self->spell_adapter, load->check_spelling);
+  editor_text_buffer_spell_adapter_set_enabled (self->spell_adapter,
+                                                g_settings_get_boolean (shared_settings, "spellcheck"));
 
   _editor_document_unmark_busy (self);
 
@@ -1207,7 +1226,8 @@ editor_document_do_load (EditorDocument *self,
       editor_document_set_busy_progress (self, 1, 2, 1.0);
       _editor_document_unmark_busy (self);
       gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (self), TRUE);
-      editor_text_buffer_spell_adapter_set_enabled (self->spell_adapter, load->check_spelling);
+      editor_text_buffer_spell_adapter_set_enabled (self->spell_adapter,
+                                                    g_settings_get_boolean (shared_settings, "spellcheck"));
       g_task_return_boolean (task, TRUE);
       return;
     }
@@ -1432,9 +1452,6 @@ _editor_document_load_async (EditorDocument      *self,
   if (gtk_source_buffer_get_highlight_syntax (GTK_SOURCE_BUFFER (self)))
     load->highlight_syntax = TRUE;
 
-  if (editor_text_buffer_spell_adapter_get_enabled (self->spell_adapter))
-    load->check_spelling = TRUE;
-
   task = g_task_new (self, cancellable, callback, user_data);
   g_task_set_source_tag (task, _editor_document_load_async);
   g_task_set_task_data (task, load, (GDestroyNotify) load_free);


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