[gspell/wip/current-word: 2/2] inline-checker-gtv: subtract the adjusted subregion from scan_region
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gspell/wip/current-word: 2/2] inline-checker-gtv: subtract the adjusted subregion from scan_region
- Date: Fri, 11 Dec 2015 17:03:55 +0000 (UTC)
commit d1e7b3395df631b8d5639d395878a391c394cff3
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Dec 11 17:58:22 2015 +0100
inline-checker-gtv: subtract the adjusted subregion from scan_region
In check_subregion(), @start and @end are now adjusted differently than
before, to not check the neighbors. So instead of having const
parameters, have in-out params so we can subtract the adjusted subregion
from scan_region.
gspell/gspell-inline-checker-gtv.c | 91 ++++++++++++++----------------------
1 files changed, 36 insertions(+), 55 deletions(-)
---
diff --git a/gspell/gspell-inline-checker-gtv.c b/gspell/gspell-inline-checker-gtv.c
index a232d7f..a685506 100644
--- a/gspell/gspell-inline-checker-gtv.c
+++ b/gspell/gspell-inline-checker-gtv.c
@@ -162,53 +162,48 @@ adjust_iters (GtkTextIter *start,
static void
check_subregion (GspellInlineCheckerGtv *spell,
- const GtkTextIter *start,
- const GtkTextIter *end)
+ GtkTextIter *start,
+ GtkTextIter *end)
{
- GtkTextIter start_adjusted;
- GtkTextIter end_adjusted;
GtkTextIter word_start;
g_assert_cmpint (gtk_text_iter_compare (start, end), <=, 0);
- start_adjusted = *start;
- end_adjusted = *end;
-
- if (gtk_text_iter_inside_word (&start_adjusted) &&
- !gtk_text_iter_starts_word (&start_adjusted))
+ if (gtk_text_iter_inside_word (start) &&
+ !gtk_text_iter_starts_word (start))
{
- gtk_text_iter_backward_word_start (&start_adjusted);
+ gtk_text_iter_backward_word_start (start);
}
- if (gtk_text_iter_inside_word (&end_adjusted) &&
- !gtk_text_iter_starts_word (&end_adjusted))
+ if (gtk_text_iter_inside_word (end) &&
+ !gtk_text_iter_starts_word (end))
{
- gtk_text_iter_forward_word_end (&end_adjusted);
+ gtk_text_iter_forward_word_end (end);
}
gtk_text_buffer_remove_tag (spell->buffer,
spell->tag_highlight,
- &start_adjusted,
- &end_adjusted);
+ start,
+ end);
- word_start = start_adjusted;
+ word_start = *start;
if (!gtk_text_iter_starts_word (&word_start))
{
gtk_text_iter_forward_word_end (&word_start);
/* Didn't move, there is no words after @start_adjusted. */
- if (gtk_text_iter_equal (&word_start, &start_adjusted))
+ if (gtk_text_iter_equal (&word_start, start))
{
return;
}
gtk_text_iter_backward_word_start (&word_start);
g_assert (gtk_text_iter_starts_word (&word_start));
- g_assert_cmpint (gtk_text_iter_compare (&start_adjusted, &word_start), <, 0);
+ g_assert_cmpint (gtk_text_iter_compare (start, &word_start), <, 0);
}
- while (_gspell_utils_skip_no_spell_check (&word_start, &end_adjusted) &&
- gtk_text_iter_compare (&word_start, &end_adjusted) < 0)
+ while (_gspell_utils_skip_no_spell_check (&word_start, end) &&
+ gtk_text_iter_compare (&word_start, end) < 0)
{
GtkTextIter word_end;
GtkTextIter next_word_start;
@@ -218,7 +213,7 @@ check_subregion (GspellInlineCheckerGtv *spell,
word_end = word_start;
gtk_text_iter_forward_word_end (&word_end);
- g_assert_cmpint (gtk_text_iter_compare (&word_end, &end_adjusted), <=, 0);
+ g_assert_cmpint (gtk_text_iter_compare (&word_end, end), <=, 0);
check_word (spell, &word_start, &word_end);
@@ -239,35 +234,6 @@ check_subregion (GspellInlineCheckerGtv *spell,
}
static void
-check_region (GspellInlineCheckerGtv *spell,
- GtkTextRegion *region)
-{
- GtkTextRegionIterator region_iter;
-
- if (region == NULL)
- {
- return;
- }
-
- gtk_text_region_get_iterator (region, ®ion_iter, 0);
-
- while (!gtk_text_region_iterator_is_end (®ion_iter))
- {
- GtkTextIter start;
- GtkTextIter end;
-
- if (!gtk_text_region_iterator_get_subregion (®ion_iter, &start, &end))
- {
- return;
- }
-
- check_subregion (spell, &start, &end);
-
- gtk_text_region_iterator_next (®ion_iter);
- }
-}
-
-static void
get_visible_region (GtkTextView *view,
GtkTextIter *start,
GtkTextIter *end)
@@ -338,6 +304,7 @@ check_visible_region_in_view (GspellInlineCheckerGtv *spell,
GtkTextIter visible_start;
GtkTextIter visible_end;
GtkTextRegion *intersect;
+ GtkTextRegionIterator intersect_iter;
if (spell->scan_region == NULL)
{
@@ -355,12 +322,26 @@ check_visible_region_in_view (GspellInlineCheckerGtv *spell,
return;
}
- check_region (spell, intersect);
- gtk_text_region_destroy (intersect);
+ gtk_text_region_get_iterator (intersect, &intersect_iter, 0);
+
+ while (!gtk_text_region_iterator_is_end (&intersect_iter))
+ {
+ GtkTextIter start;
+ GtkTextIter end;
+
+ if (!gtk_text_region_iterator_get_subregion (&intersect_iter, &start, &end))
+ {
+ return;
+ }
- gtk_text_region_subtract (spell->scan_region,
- &visible_start,
- &visible_end);
+ check_subregion (spell, &start, &end);
+
+ gtk_text_region_subtract (spell->scan_region, &start, &end);
+
+ gtk_text_region_iterator_next (&intersect_iter);
+ }
+
+ gtk_text_region_destroy (intersect);
if (is_text_region_empty (spell->scan_region))
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]