[gnome-text-editor] spellcheck: separate before/after operations on adapter
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-text-editor] spellcheck: separate before/after operations on adapter
- Date: Fri, 16 Jul 2021 23:21:35 +0000 (UTC)
commit 5bd8d0861fe41d8cb4bb964bcd70fc521e8d2f20
Author: Christian Hergert <chergert redhat com>
Date: Fri Jul 16 16:19:36 2021 -0700
spellcheck: separate before/after operations on adapter
src/editor-document.c | 13 +++++++----
src/editor-text-buffer-spell-adapter.c | 34 ++++++++++++++++-------------
src/editor-text-buffer-spell-adapter.h | 40 +++++++++++++++++++---------------
3 files changed, 51 insertions(+), 36 deletions(-)
---
diff --git a/src/editor-document.c b/src/editor-document.c
index f1d8432..a70ae2b 100644
--- a/src/editor-document.c
+++ b/src/editor-document.c
@@ -238,13 +238,15 @@ editor_document_insert_text (GtkTextBuffer *buffer,
line = gtk_text_iter_get_line (pos);
offset = gtk_text_iter_get_offset (pos);
+ length = g_utf8_strlen (new_text, new_text_length);
- GTK_TEXT_BUFFER_CLASS (editor_document_parent_class)->insert_text (buffer, pos, new_text, new_text_length);
+ if (length > 0)
+ editor_text_buffer_spell_adapter_before_insert_text (self->spell_adapter, offset, length);
- length = gtk_text_iter_get_offset (pos) - offset;
+ GTK_TEXT_BUFFER_CLASS (editor_document_parent_class)->insert_text (buffer, pos, new_text, new_text_length);
if (length > 0)
- editor_text_buffer_spell_adapter_insert_text (self->spell_adapter, offset, length);
+ editor_text_buffer_spell_adapter_after_insert_text (self->spell_adapter, offset, length);
if (offset < TITLE_MAX_LEN && editor_document_get_file (self) == NULL)
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TITLE]);
@@ -270,10 +272,13 @@ editor_document_delete_range (GtkTextBuffer *buffer,
offset = gtk_text_iter_get_offset (start);
length = gtk_text_iter_get_offset (end) - offset;
+ if (length > 0)
+ editor_text_buffer_spell_adapter_before_delete_range (self->spell_adapter, offset, length);
+
GTK_TEXT_BUFFER_CLASS (editor_document_parent_class)->delete_range (buffer, start, end);
if (length > 0)
- editor_text_buffer_spell_adapter_delete_range (self->spell_adapter, offset, length);
+ editor_text_buffer_spell_adapter_after_delete_range (self->spell_adapter, offset, length);
if (offset < TITLE_MAX_LEN && editor_document_get_file (self) == NULL)
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TITLE]);
diff --git a/src/editor-text-buffer-spell-adapter.c b/src/editor-text-buffer-spell-adapter.c
index 3d09f51..f7e6a31 100644
--- a/src/editor-text-buffer-spell-adapter.c
+++ b/src/editor-text-buffer-spell-adapter.c
@@ -604,32 +604,36 @@ mark_unchecked (EditorTextBufferSpellAdapter *self,
}
void
-editor_text_buffer_spell_adapter_insert_text (EditorTextBufferSpellAdapter *self,
- guint offset,
- guint length)
+editor_text_buffer_spell_adapter_before_insert_text (EditorTextBufferSpellAdapter *self,
+ guint offset,
+ guint length)
{
-
- g_return_if_fail (EDITOR_IS_TEXT_BUFFER_SPELL_ADAPTER (self));
- g_return_if_fail (GTK_IS_TEXT_BUFFER (self->buffer));
- g_return_if_fail (length > 0);
-
_cjh_text_region_insert (self->region, offset, length, RUN_UNCHECKED);
+}
+
+void
+editor_text_buffer_spell_adapter_after_insert_text (EditorTextBufferSpellAdapter *self,
+ guint offset,
+ guint length)
+{
if (self->enabled)
mark_unchecked (self, offset, length);
}
void
-editor_text_buffer_spell_adapter_delete_range (EditorTextBufferSpellAdapter *self,
- guint offset,
- guint length)
+editor_text_buffer_spell_adapter_before_delete_range (EditorTextBufferSpellAdapter *self,
+ guint offset,
+ guint length)
{
- g_return_if_fail (EDITOR_IS_TEXT_BUFFER_SPELL_ADAPTER (self));
- g_return_if_fail (self->buffer != NULL);
- g_return_if_fail (length > 0);
-
_cjh_text_region_remove (self->region, offset, length);
+}
+void
+editor_text_buffer_spell_adapter_after_delete_range (EditorTextBufferSpellAdapter *self,
+ guint offset,
+ guint length)
+{
if (self->enabled)
mark_unchecked (self, offset, 0);
}
diff --git a/src/editor-text-buffer-spell-adapter.h b/src/editor-text-buffer-spell-adapter.h
index 111309d..10637e4 100644
--- a/src/editor-text-buffer-spell-adapter.h
+++ b/src/editor-text-buffer-spell-adapter.h
@@ -30,22 +30,28 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (EditorTextBufferSpellAdapter, editor_text_buffer_spell_adapter, EDITOR,
TEXT_BUFFER_SPELL_ADAPTER, GObject)
-EditorTextBufferSpellAdapter *editor_text_buffer_spell_adapter_new (GtkTextBuffer
*buffer,
- EditorSpellChecker
*checker);
-GtkTextBuffer *editor_text_buffer_spell_adapter_get_buffer (EditorTextBufferSpellAdapter
*self);
-EditorSpellChecker *editor_text_buffer_spell_adapter_get_checker (EditorTextBufferSpellAdapter
*self);
-void editor_text_buffer_spell_adapter_set_checker (EditorTextBufferSpellAdapter
*self,
- EditorSpellChecker
*checker);
-void editor_text_buffer_spell_adapter_insert_text (EditorTextBufferSpellAdapter
*self,
- guint
offset,
- guint
len);
-void editor_text_buffer_spell_adapter_delete_range (EditorTextBufferSpellAdapter
*self,
- guint
offset,
- guint
len);
-void editor_text_buffer_spell_adapter_cursor_moved (EditorTextBufferSpellAdapter
*self,
- guint
position);
-const char *editor_text_buffer_spell_adapter_get_language (EditorTextBufferSpellAdapter
*self);
-void editor_text_buffer_spell_adapter_set_language (EditorTextBufferSpellAdapter
*self,
- const char
*language);
+EditorTextBufferSpellAdapter *editor_text_buffer_spell_adapter_new (GtkTextBuffer
*buffer,
+ EditorSpellChecker
*checker);
+GtkTextBuffer *editor_text_buffer_spell_adapter_get_buffer
(EditorTextBufferSpellAdapter *self);
+EditorSpellChecker *editor_text_buffer_spell_adapter_get_checker
(EditorTextBufferSpellAdapter *self);
+void editor_text_buffer_spell_adapter_set_checker
(EditorTextBufferSpellAdapter *self,
+ EditorSpellChecker
*checker);
+void editor_text_buffer_spell_adapter_before_insert_text
(EditorTextBufferSpellAdapter *self,
+ guint
offset,
+ guint
len);
+void editor_text_buffer_spell_adapter_after_insert_text
(EditorTextBufferSpellAdapter *self,
+ guint
offset,
+ guint
len);
+void editor_text_buffer_spell_adapter_before_delete_range
(EditorTextBufferSpellAdapter *self,
+ guint
offset,
+ guint
len);
+void editor_text_buffer_spell_adapter_after_delete_range
(EditorTextBufferSpellAdapter *self,
+ guint
offset,
+ guint
len);
+void editor_text_buffer_spell_adapter_cursor_moved
(EditorTextBufferSpellAdapter *self,
+ guint
position);
+const char *editor_text_buffer_spell_adapter_get_language
(EditorTextBufferSpellAdapter *self);
+void editor_text_buffer_spell_adapter_set_language
(EditorTextBufferSpellAdapter *self,
+ const char
*language);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]