[gspell/wip/current-word] inline-checker-text-buffer: don't check current word while typing
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gspell/wip/current-word] inline-checker-text-buffer: don't check current word while typing
- Date: Thu, 11 Feb 2016 18:39:35 +0000 (UTC)
commit 54a814cca73435123a31de90324aaa39e85781f8
Author: Sébastien Wilmet <swilmet gnome org>
Date: Thu Feb 11 19:38:43 2016 +0100
inline-checker-text-buffer: don't check current word while typing
gspell/gspell-inline-checker-text-buffer.c | 52 ++++++++++++++++++++++++++++
1 files changed, 52 insertions(+), 0 deletions(-)
---
diff --git a/gspell/gspell-inline-checker-text-buffer.c b/gspell/gspell-inline-checker-text-buffer.c
index 4b2996b..12a6f51 100644
--- a/gspell/gspell-inline-checker-text-buffer.c
+++ b/gspell/gspell-inline-checker-text-buffer.c
@@ -50,6 +50,11 @@ struct _GspellInlineCheckerTextBuffer
GspellTextRegion *scan_region;
guint timeout_id;
+ /* When a word is being typed, it should not be marked as misspelled,
+ * because it would be annoying.
+ */
+ guint check_current_word : 1;
+
/* If the unit test mode is enabled, there is no timeouts, and the whole
* buffer is scanned synchronously.
* The unit test mode tries to follow as most as possible the same code
@@ -259,6 +264,46 @@ is_text_region_empty (GspellTextRegion *region)
}
static void
+subtract_current_word (GspellTextRegion *region)
+{
+ GtkTextBuffer *buffer;
+ GtkTextIter insert_iter;
+ GtkTextIter word_start;
+ GtkTextIter word_end;
+
+ buffer = _gspell_text_region_get_buffer (region);
+ if (buffer == NULL)
+ {
+ return;
+ }
+
+ if (gtk_text_buffer_get_has_selection (buffer))
+ {
+ return;
+ }
+
+ gtk_text_buffer_get_iter_at_mark (buffer,
+ &insert_iter,
+ gtk_text_buffer_get_insert (buffer));
+
+ word_start = insert_iter;
+ if (gtk_text_iter_ends_word (&word_start) ||
+ (gtk_text_iter_inside_word (&word_start) &&
+ !gtk_text_iter_starts_word (&word_start)))
+ {
+ gtk_text_iter_backward_word_start (&word_start);
+ }
+
+ word_end = insert_iter;
+ if (gtk_text_iter_inside_word (&word_end))
+ {
+ gtk_text_iter_forward_word_end (&word_end);
+ }
+
+ _gspell_text_region_subtract (region, &word_start, &word_end);
+}
+
+static void
check_visible_region_in_view (GspellInlineCheckerTextBuffer *spell,
GtkTextView *view)
{
@@ -291,6 +336,8 @@ check_visible_region_in_view (GspellInlineCheckerTextBuffer *spell,
return;
}
+ subtract_current_word (intersect);
+
if (is_text_region_empty (intersect))
{
_gspell_text_region_destroy (intersect);
@@ -410,6 +457,7 @@ recheck_all (GspellInlineCheckerTextBuffer *spell)
gtk_text_buffer_get_bounds (spell->buffer, &start, &end);
+ spell->check_current_word = TRUE;
add_subregion_to_scan (spell, &start, &end);
check_visible_region (spell);
}
@@ -441,6 +489,7 @@ insert_text_after_cb (GtkTextBuffer *buffer,
gtk_text_iter_forward_word_end (&end);
}
+ spell->check_current_word = FALSE;
add_subregion_to_scan (spell, &start, &end);
install_timeout (spell, TIMEOUT_DURATION_BUFFER_MODIFIED);
}
@@ -472,6 +521,7 @@ delete_range_after_cb (GtkTextBuffer *buffer,
gtk_text_iter_forward_word_end (&end_adjusted);
}
+ spell->check_current_word = FALSE;
add_subregion_to_scan (spell, &start_adjusted, &end_adjusted);
install_timeout (spell, TIMEOUT_DURATION_BUFFER_MODIFIED);
}
@@ -1159,6 +1209,7 @@ _gspell_inline_checker_text_buffer_class_init (GspellInlineCheckerTextBufferClas
static void
_gspell_inline_checker_text_buffer_init (GspellInlineCheckerTextBuffer *spell)
{
+ spell->check_current_word = TRUE;
}
GspellInlineCheckerTextBuffer *
@@ -1222,6 +1273,7 @@ _gspell_inline_checker_text_buffer_attach_view (GspellInlineCheckerTextBuffer *s
spell->views = g_slist_prepend (spell->views, view);
+ spell->check_current_word = TRUE;
check_visible_region_in_view (spell, view);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]