[gnome-text-editor] spellcheck: give cursor position to adapter



commit 11fa80465b3693fb0340041da9d19d8c435bfc4e
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jun 25 16:27:32 2021 -0700

    spellcheck: give cursor position to adapter
    
    So that we know when we should avoid checking a word under the cursor.

 src/editor-document.c                  | 10 +++++++++-
 src/editor-text-buffer-spell-adapter.c |  5 ++++-
 src/editor-text-buffer-spell-adapter.h |  3 ++-
 3 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/src/editor-document.c b/src/editor-document.c
index 5c88059..96ba399 100644
--- a/src/editor-document.c
+++ b/src/editor-document.c
@@ -312,7 +312,15 @@ editor_document_monitor_notify_changed_cb (EditorDocument      *self,
 static void
 on_cursor_moved_cb (EditorDocument *self)
 {
-  editor_text_buffer_spell_adapter_cursor_moved (self->spell_adapter);
+  GtkTextMark *mark;
+  GtkTextIter iter;
+
+  mark = gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (self));
+  gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (self), &iter, mark);
+
+  editor_text_buffer_spell_adapter_cursor_moved (self->spell_adapter,
+                                                 gtk_text_iter_get_offset (&iter));
+
 }
 
 static void
diff --git a/src/editor-text-buffer-spell-adapter.c b/src/editor-text-buffer-spell-adapter.c
index 0549e96..2257332 100644
--- a/src/editor-text-buffer-spell-adapter.c
+++ b/src/editor-text-buffer-spell-adapter.c
@@ -34,6 +34,7 @@ struct _EditorTextBufferSpellAdapter
   GtkTextBuffer      *buffer;
   EditorSpellChecker *checker;
   CjhTextRegion      *region;
+  guint               cursor_position;
 };
 
 G_DEFINE_TYPE (EditorTextBufferSpellAdapter, editor_text_buffer_spell_adapter, G_TYPE_OBJECT)
@@ -225,9 +226,11 @@ editor_text_buffer_spell_adapter_delete_range (EditorTextBufferSpellAdapter *sel
 }
 
 void
-editor_text_buffer_spell_adapter_cursor_moved (EditorTextBufferSpellAdapter *self)
+editor_text_buffer_spell_adapter_cursor_moved (EditorTextBufferSpellAdapter *self,
+                                               guint                         position)
 {
   g_return_if_fail (EDITOR_IS_TEXT_BUFFER_SPELL_ADAPTER (self));
   g_return_if_fail (self->buffer != NULL);
 
+  self->cursor_position = position;
 }
diff --git a/src/editor-text-buffer-spell-adapter.h b/src/editor-text-buffer-spell-adapter.h
index bd676ac..47e3f6b 100644
--- a/src/editor-text-buffer-spell-adapter.h
+++ b/src/editor-text-buffer-spell-adapter.h
@@ -42,6 +42,7 @@ void                          editor_text_buffer_spell_adapter_insert_text  (Edi
 void                          editor_text_buffer_spell_adapter_delete_range (EditorTextBufferSpellAdapter 
*self,
                                                                              guint                         
offset,
                                                                              guint                         
len);
-void                          editor_text_buffer_spell_adapter_cursor_moved (EditorTextBufferSpellAdapter 
*self);
+void                          editor_text_buffer_spell_adapter_cursor_moved (EditorTextBufferSpellAdapter 
*self,
+                                                                             guint                         
position);
 
 G_END_DECLS


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