[gnome-text-editor] spellcheck: do less when spellcheck is not active
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-text-editor] spellcheck: do less when spellcheck is not active
- Date: Thu, 14 Oct 2021 06:12:31 +0000 (UTC)
commit 0738a4de5ee44a7bfc92ff2da66d59524ac39659
Author: Christian Hergert <chergert redhat com>
Date: Wed Oct 13 23:01:28 2021 -0700
spellcheck: do less when spellcheck is not active
We want to avoid doing pretty much anything when spellcheck is not active
because maintaining the extra btree is just overhead.
This also fixes #189 by not trying to update the btree when the no-spell-
check tag span is updated.
Fixes #189
src/editor-text-buffer-spell-adapter.c | 32 ++++++++++++++++++++++++++------
1 file changed, 26 insertions(+), 6 deletions(-)
---
diff --git a/src/editor-text-buffer-spell-adapter.c b/src/editor-text-buffer-spell-adapter.c
index eb96ad4..ba4c204 100644
--- a/src/editor-text-buffer-spell-adapter.c
+++ b/src/editor-text-buffer-spell-adapter.c
@@ -307,16 +307,26 @@ editor_text_buffer_spell_adapter_invalidate_all (EditorTextBufferSpellAdapter *s
g_assert (EDITOR_IS_TEXT_BUFFER_SPELL_ADAPTER (self));
- length = _cjh_text_region_get_length (self->region);
+ if (!self->enabled)
+ return;
- if (length > 0)
+ /* We remove using the known length from the region */
+ if ((length = _cjh_text_region_get_length (self->region)) > 0)
{
- _cjh_text_region_replace (self->region, 0, length - 1, RUN_UNCHECKED);
+ _cjh_text_region_remove (self->region, 0, length - 1);
editor_text_buffer_spell_adapter_queue_update (self);
}
+ /* We add using the length from the buffer because if we were not
+ * enabled previously, the textregion would be empty.
+ */
gtk_text_buffer_get_bounds (self->buffer, &begin, &end);
- gtk_text_buffer_remove_tag (self->buffer, self->tag, &begin, &end);
+ if (!gtk_text_iter_equal (&begin, &end))
+ {
+ length = gtk_text_iter_get_offset (&end) - gtk_text_iter_get_offset (&begin);
+ _cjh_text_region_insert (self->region, 0, length, RUN_UNCHECKED);
+ gtk_text_buffer_remove_tag (self->buffer, self->tag, &begin, &end);
+ }
}
static void
@@ -365,6 +375,9 @@ invalidate_tag_region_cb (EditorTextBufferSpellAdapter *self,
g_assert (GTK_IS_TEXT_TAG (tag));
g_assert (GTK_IS_TEXT_BUFFER (buffer));
+ if (!self->enabled)
+ return;
+
if (tag == self->no_spell_check_tag)
{
gsize begin_offset = gtk_text_iter_get_offset (begin);
@@ -451,6 +464,8 @@ editor_text_buffer_spell_adapter_set_enabled (EditorTextBufferSpellAdapter *self
}
editor_text_buffer_spell_adapter_invalidate_all (self);
+ editor_text_buffer_spell_adapter_queue_update (self);
+
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ENABLED]);
}
}
@@ -665,7 +680,8 @@ editor_text_buffer_spell_adapter_before_insert_text (EditorTextBufferSpellAdapte
guint offset,
guint length)
{
- _cjh_text_region_insert (self->region, offset, length, RUN_UNCHECKED);
+ if (self->enabled)
+ _cjh_text_region_insert (self->region, offset, length, RUN_UNCHECKED);
}
@@ -683,7 +699,8 @@ editor_text_buffer_spell_adapter_before_delete_range (EditorTextBufferSpellAdapt
guint offset,
guint length)
{
- _cjh_text_region_remove (self->region, offset, length);
+ if (self->enabled)
+ _cjh_text_region_remove (self->region, offset, length);
}
void
@@ -729,6 +746,9 @@ editor_text_buffer_spell_adapter_cursor_moved (EditorTextBufferSpellAdapter *sel
g_return_if_fail (EDITOR_IS_TEXT_BUFFER_SPELL_ADAPTER (self));
g_return_if_fail (self->buffer != NULL);
+ if (!self->enabled)
+ return;
+
self->incoming_cursor_position = position;
g_clear_handle_id (&self->queued_cursor_moved, g_source_remove);
self->queued_cursor_moved = g_timeout_add_full (G_PRIORITY_LOW,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]