[gtksourceview/wip/public-region] region: add get_bounds() function
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/public-region] region: add get_bounds() function
- Date: Sat, 2 Apr 2016 10:52:59 +0000 (UTC)
commit 314586d863ffbd6778d3eacb213a29f7455f38fa
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat Apr 2 12:48:44 2016 +0200
region: add get_bounds() function
gtksourceview/gtksourceregion.c | 30 ++++++++++++++++++
gtksourceview/gtksourceregion.h | 5 +++
gtksourceview/gtksourcesearchcontext.c | 53 ++++++--------------------------
3 files changed, 45 insertions(+), 43 deletions(-)
---
diff --git a/gtksourceview/gtksourceregion.c b/gtksourceview/gtksourceregion.c
index 17ad85b..77740bc 100644
--- a/gtksourceview/gtksourceregion.c
+++ b/gtksourceview/gtksourceregion.c
@@ -534,6 +534,36 @@ gtk_source_region_is_empty (GtkSourceRegion *region)
return TRUE;
}
+gboolean
+gtk_source_region_get_bounds (GtkSourceRegion *region,
+ GtkTextIter *start,
+ GtkTextIter *end)
+{
+ g_return_val_if_fail (region != NULL, FALSE);
+
+ if (region->buffer == NULL ||
+ gtk_source_region_is_empty (region))
+ {
+ return FALSE;
+ }
+
+ g_assert (region->subregions != NULL);
+
+ if (start != NULL)
+ {
+ Subregion *first_subregion = region->subregions->data;
+ gtk_text_buffer_get_iter_at_mark (region->buffer, start, first_subregion->start);
+ }
+
+ if (end != NULL)
+ {
+ Subregion *last_subregion = g_list_last (region->subregions)->data;
+ gtk_text_buffer_get_iter_at_mark (region->buffer, end, last_subregion->end);
+ }
+
+ return TRUE;
+}
+
guint
gtk_source_region_get_subregion_count (GtkSourceRegion *region)
{
diff --git a/gtksourceview/gtksourceregion.h b/gtksourceview/gtksourceregion.h
index 272a460..804c97c 100644
--- a/gtksourceview/gtksourceregion.h
+++ b/gtksourceview/gtksourceregion.h
@@ -71,6 +71,11 @@ GTK_SOURCE_INTERNAL
gboolean gtk_source_region_is_empty (GtkSourceRegion *region);
GTK_SOURCE_INTERNAL
+gboolean gtk_source_region_get_bounds (GtkSourceRegion *region,
+ GtkTextIter *start,
+ GtkTextIter *end);
+
+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 36f26c7..9a770e0 100644
--- a/gtksourceview/gtksourcesearchcontext.c
+++ b/gtksourceview/gtksourcesearchcontext.c
@@ -1578,33 +1578,16 @@ static void
scan_all_region (GtkSourceSearchContext *search,
GtkSourceRegion *region_to_highlight)
{
- guint nb_subregions = gtk_source_region_get_subregion_count (region_to_highlight);
GtkTextIter start_search;
GtkTextIter end_search;
- if (nb_subregions == 0)
+ if (!gtk_source_region_get_bounds (region_to_highlight,
+ &start_search,
+ &end_search))
{
return;
}
- if (!gtk_source_region_nth_subregion (region_to_highlight,
- 0,
- &start_search,
- NULL))
- {
- return;
- }
-
- if (!gtk_source_region_nth_subregion (region_to_highlight,
- nb_subregions - 1,
- NULL,
- &end_search))
- {
- return;
- }
-
- gtk_text_iter_order (&start_search, &end_search);
-
scan_subregion (search, &start_search, &end_search);
}
@@ -1784,25 +1767,10 @@ regex_search_handle_high_priority_region (GtkSourceSearchContext *search)
GtkTextIter end;
GtkSourceRegion *region;
GtkSourceRegionIter region_iter;
- guint nb_subregions = gtk_source_region_get_subregion_count (search->priv->high_priority_region);
-
- if (nb_subregions == 0)
- {
- return;
- }
-
- if (!gtk_source_region_nth_subregion (search->priv->high_priority_region,
- 0,
- &start,
- NULL))
- {
- return;
- }
- if (!gtk_source_region_nth_subregion (search->priv->high_priority_region,
- nb_subregions - 1,
- NULL,
- &end))
+ if (!gtk_source_region_get_bounds (search->priv->high_priority_region,
+ &start,
+ &end))
{
return;
}
@@ -2034,7 +2002,7 @@ regex_search_scan_next_chunk (GtkSourceSearchContext *search)
return;
}
- if (!gtk_source_region_nth_subregion (search->priv->scan_region, 0, &chunk_start, NULL))
+ if (!gtk_source_region_get_bounds (search->priv->scan_region, &chunk_start, NULL))
{
return;
}
@@ -3839,10 +3807,9 @@ _gtk_source_search_context_update_highlight (GtkSourceSearchContext *search,
{
GtkTextIter region_start;
- if (!gtk_source_region_nth_subregion (search->priv->scan_region,
- 0,
- ®ion_start,
- NULL))
+ if (!gtk_source_region_get_bounds (search->priv->scan_region,
+ ®ion_start,
+ NULL))
{
return;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]