[gtksourceview/wip/public-region] region: add is_empty() function
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/public-region] region: add is_empty() function
- Date: Sat, 2 Apr 2016 10:16:42 +0000 (UTC)
commit e0fa3b64cb9c97ca5e1c0063e9ba4f069943de18
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat Apr 2 11:57:05 2016 +0200
region: add is_empty() function
.../words/gtksourcecompletionwordsbuffer.c | 37 +---------
gtksourceview/gtksourceregion.c | 41 ++++++++++
gtksourceview/gtksourceregion.h | 3 +
gtksourceview/gtksourcesearchcontext.c | 80 ++++++--------------
4 files changed, 68 insertions(+), 93 deletions(-)
---
diff --git a/gtksourceview/completion-providers/words/gtksourcecompletionwordsbuffer.c
b/gtksourceview/completion-providers/words/gtksourcecompletionwordsbuffer.c
index 4762e6e..6a050c6 100644
--- a/gtksourceview/completion-providers/words/gtksourcecompletionwordsbuffer.c
+++ b/gtksourceview/completion-providers/words/gtksourcecompletionwordsbuffer.c
@@ -302,39 +302,6 @@ scan_region (GtkSourceCompletionWordsBuffer *buffer,
return nb_lines_scanned;
}
-/* A TextRegion can contain empty subregions. So checking the number of
- * subregions is not sufficient.
- * When calling gtk_source_region_add() with equal iters, the subregion is not
- * added. But when a subregion becomes empty, due to text deletion, the
- * subregion is not removed from the TextRegion.
- */
-static gboolean
-is_text_region_empty (GtkSourceRegion *region)
-{
- GtkSourceRegionIter region_iter;
-
- gtk_source_region_get_start_region_iter (region, ®ion_iter);
-
- while (!gtk_source_region_iter_is_end (®ion_iter))
- {
- GtkTextIter region_start;
- GtkTextIter region_end;
-
- gtk_source_region_iter_get_subregion (®ion_iter,
- ®ion_start,
- ®ion_end);
-
- if (!gtk_text_iter_equal (®ion_start, ®ion_end))
- {
- return FALSE;
- }
-
- gtk_source_region_iter_next (®ion_iter);
- }
-
- return TRUE;
-}
-
static gboolean
idle_scan_regions (GtkSourceCompletionWordsBuffer *buffer)
{
@@ -371,7 +338,7 @@ idle_scan_regions (GtkSourceCompletionWordsBuffer *buffer)
&start,
&stop);
- if (is_text_region_empty (buffer->priv->scan_region))
+ if (gtk_source_region_is_empty (buffer->priv->scan_region))
{
buffer->priv->batch_scan_id = 0;
return G_SOURCE_REMOVE;
@@ -668,7 +635,7 @@ on_library_lock (GtkSourceCompletionWordsBuffer *buffer)
static void
on_library_unlock (GtkSourceCompletionWordsBuffer *buffer)
{
- if (!is_text_region_empty (buffer->priv->scan_region))
+ if (!gtk_source_region_is_empty (buffer->priv->scan_region))
{
install_initiate_scan (buffer);
}
diff --git a/gtksourceview/gtksourceregion.c b/gtksourceview/gtksourceregion.c
index c1bd9b0..dcef1c1 100644
--- a/gtksourceview/gtksourceregion.c
+++ b/gtksourceview/gtksourceregion.c
@@ -493,6 +493,47 @@ gtk_source_region_subtract (GtkSourceRegion *region,
DEBUG (_gtk_source_region_debug_print (region));
}
+/* A #GtkSourceRegion can contain empty subregions. So checking the number of
+ * subregions is not sufficient.
+ * When calling gtk_source_region_add() with equal iters, the subregion is not
+ * added. But when a subregion becomes empty, due to text deletion, the
+ * subregion is not removed from the #GtkSourceRegion.
+ */
+gboolean
+gtk_source_region_is_empty (GtkSourceRegion *region)
+{
+ GtkSourceRegionIter region_iter;
+
+ if (region == NULL)
+ {
+ return TRUE;
+ }
+
+ gtk_source_region_get_start_region_iter (region, ®ion_iter);
+
+ while (!gtk_source_region_iter_is_end (®ion_iter))
+ {
+ GtkTextIter subregion_start;
+ GtkTextIter subregion_end;
+
+ if (!gtk_source_region_iter_get_subregion (®ion_iter,
+ &subregion_start,
+ &subregion_end))
+ {
+ return TRUE;
+ }
+
+ if (!gtk_text_iter_equal (&subregion_start, &subregion_end))
+ {
+ return FALSE;
+ }
+
+ gtk_source_region_iter_next (®ion_iter);
+ }
+
+ return TRUE;
+}
+
guint
gtk_source_region_get_subregion_count (GtkSourceRegion *region)
{
diff --git a/gtksourceview/gtksourceregion.h b/gtksourceview/gtksourceregion.h
index 7ede683..5b1a519 100644
--- a/gtksourceview/gtksourceregion.h
+++ b/gtksourceview/gtksourceregion.h
@@ -68,6 +68,9 @@ GtkSourceRegion * gtk_source_region_intersect (GtkSourceRegion *region,
const GtkTextIter *_end);
GTK_SOURCE_INTERNAL
+gboolean gtk_source_region_is_empty (GtkSourceRegion *region);
+
+GTK_SOURCE_INTERNAL
guint gtk_source_region_get_subregion_count (GtkSourceRegion *region);
GTK_SOURCE_INTERNAL
diff --git a/gtksourceview/gtksourcesearchcontext.c b/gtksourceview/gtksourcesearchcontext.c
index a5b93ac..36f26c7 100644
--- a/gtksourceview/gtksourcesearchcontext.c
+++ b/gtksourceview/gtksourcesearchcontext.c
@@ -417,47 +417,6 @@ text_tag_set_highest_priority (GtkTextTag *tag,
gtk_text_tag_set_priority (tag, n - 1);
}
-/* A TextRegion can contain empty subregions. So checking the number of
- * subregions is not sufficient.
- * When calling gtk_source_region_add() with equal iters, the subregion is not
- * added. But when a subregion becomes empty, due to text deletion, the
- * subregion is not removed from the TextRegion.
- */
-static gboolean
-is_text_region_empty (GtkSourceRegion *region)
-{
- GtkSourceRegionIter region_iter;
-
- if (region == NULL)
- {
- return TRUE;
- }
-
- gtk_source_region_get_start_region_iter (region, ®ion_iter);
-
- while (!gtk_source_region_iter_is_end (®ion_iter))
- {
- GtkTextIter region_start;
- GtkTextIter region_end;
-
- if (!gtk_source_region_iter_get_subregion (®ion_iter,
- ®ion_start,
- ®ion_end))
- {
- return TRUE;
- }
-
- if (!gtk_text_iter_equal (®ion_start, ®ion_end))
- {
- return FALSE;
- }
-
- gtk_source_region_iter_next (®ion_iter);
- }
-
- return TRUE;
-}
-
/* Sets @start and @end to the first non-empty subregion.
* Returns FALSE if the region is empty.
*/
@@ -1059,7 +1018,7 @@ smart_forward_search_async_step (GtkSourceSearchContext *search,
region = gtk_source_region_intersect (search->priv->scan_region, ®ion_start, &limit);
}
- if (is_text_region_empty (region))
+ if (gtk_source_region_is_empty (region))
{
GtkTextIter match_start;
GtkTextIter match_end;
@@ -1195,7 +1154,7 @@ smart_backward_search_async_step (GtkSourceSearchContext *search,
region = gtk_source_region_intersect (search->priv->scan_region, &limit, ®ion_end);
}
- if (is_text_region_empty (region))
+ if (gtk_source_region_is_empty (region))
{
GtkTextIter match_start;
GtkTextIter match_end;
@@ -1310,7 +1269,7 @@ adjust_subregion (GtkSourceSearchContext *search,
if (gtk_text_iter_has_tag (start, search->priv->found_tag))
{
- if (is_text_region_empty (search->priv->scan_region))
+ if (gtk_source_region_is_empty (search->priv->scan_region))
{
/* 'start' is in a correct match, we can skip it. */
gtk_text_iter_forward_to_tag_toggle (start, search->priv->found_tag);
@@ -1332,7 +1291,7 @@ adjust_subregion (GtkSourceSearchContext *search,
&tag_start,
&tag_end);
- if (is_text_region_empty (region))
+ if (gtk_source_region_is_empty (region))
{
/* 'region' has already been scanned, so 'start' is in a
* correct match, we can skip it.
@@ -1359,7 +1318,7 @@ adjust_subregion (GtkSourceSearchContext *search,
if (gtk_text_iter_has_tag (end, search->priv->found_tag))
{
- if (is_text_region_empty (search->priv->scan_region))
+ if (gtk_source_region_is_empty (search->priv->scan_region))
{
/* 'end' is in a correct match, we can skip it. */
@@ -1385,7 +1344,7 @@ adjust_subregion (GtkSourceSearchContext *search,
&tag_start,
&tag_end);
- if (is_text_region_empty (region))
+ if (gtk_source_region_is_empty (region))
{
/* 'region' has already been scanned, so 'end' is in a
* correct match, we can skip it.
@@ -1518,7 +1477,7 @@ remove_occurrences_in_range (GtkSourceSearchContext *search,
&match_start,
&match_end);
- if (is_text_region_empty (region))
+ if (gtk_source_region_is_empty (region))
{
search->priv->occurrences_count--;
}
@@ -1792,7 +1751,7 @@ idle_scan_normal_search (GtkSourceSearchContext *search)
scan_region_forward (search, search->priv->scan_region);
- if (is_text_region_empty (search->priv->scan_region))
+ if (gtk_source_region_is_empty (search->priv->scan_region))
{
search->priv->idle_scan_id = 0;
@@ -2070,7 +2029,7 @@ regex_search_scan_next_chunk (GtkSourceSearchContext *search)
GtkTextIter chunk_start;
GtkTextIter chunk_end;
- if (is_text_region_empty (search->priv->scan_region))
+ if (gtk_source_region_is_empty (search->priv->scan_region))
{
return;
}
@@ -2115,7 +2074,7 @@ idle_scan_regex_search (GtkSourceSearchContext *search)
return G_SOURCE_CONTINUE;
}
- if (is_text_region_empty (search->priv->scan_region))
+ if (gtk_source_region_is_empty (search->priv->scan_region))
{
search->priv->idle_scan_id = 0;
@@ -2187,7 +2146,7 @@ smart_forward_search_step (GtkSourceSearchContext *search,
region = gtk_source_region_intersect (search->priv->scan_region, ®ion_start, &limit);
}
- if (is_text_region_empty (region))
+ if (gtk_source_region_is_empty (region))
{
if (region != NULL)
{
@@ -2286,7 +2245,7 @@ smart_backward_search_step (GtkSourceSearchContext *search,
region = gtk_source_region_intersect (search->priv->scan_region, &limit, ®ion_end);
}
- if (is_text_region_empty (region))
+ if (gtk_source_region_is_empty (region))
{
if (region != NULL)
{
@@ -3161,7 +3120,12 @@ gtk_source_search_context_get_occurrences_count (GtkSourceSearchContext *search)
{
g_return_val_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search), -1);
- return is_text_region_empty (search->priv->scan_region) ? search->priv->occurrences_count : -1;
+ if (!gtk_source_region_is_empty (search->priv->scan_region))
+ {
+ return -1;
+ }
+
+ return search->priv->occurrences_count;
}
/**
@@ -3211,7 +3175,7 @@ gtk_source_search_context_get_occurrence_position (GtkSourceSearchContext *searc
match_start,
match_end);
- empty = is_text_region_empty (region);
+ empty = gtk_source_region_is_empty (region);
if (region != NULL)
{
@@ -3251,7 +3215,7 @@ gtk_source_search_context_get_occurrence_position (GtkSourceSearchContext *searc
&iter,
match_end);
- empty = is_text_region_empty (region);
+ empty = gtk_source_region_is_empty (region);
if (region != NULL)
{
@@ -3834,7 +3798,7 @@ _gtk_source_search_context_update_highlight (GtkSourceSearchContext *search,
g_return_if_fail (end != NULL);
if (search->priv->buffer == NULL ||
- is_text_region_empty (search->priv->scan_region) ||
+ gtk_source_region_is_empty (search->priv->scan_region) ||
!search->priv->highlight)
{
return;
@@ -3844,7 +3808,7 @@ _gtk_source_search_context_update_highlight (GtkSourceSearchContext *search,
start,
end);
- if (is_text_region_empty (region_to_highlight))
+ if (gtk_source_region_is_empty (region_to_highlight))
{
if (region_to_highlight != NULL)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]