[gnome-builder/wip/libide] libide: improve fetching rectangles around regions
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/libide] libide: improve fetching rectangles around regions
- Date: Sat, 7 Mar 2015 00:24:12 +0000 (UTC)
commit 7849b7fd3ddc57396f38dcfaa3b213979d798e26
Author: Christian Hergert <christian hergert me>
Date: Fri Mar 6 16:24:05 2015 -0800
libide: improve fetching rectangles around regions
libide/ide-source-view.c | 23 ++++++++++++++++++++---
1 files changed, 20 insertions(+), 3 deletions(-)
---
diff --git a/libide/ide-source-view.c b/libide/ide-source-view.c
index e02915e..6f134f4 100644
--- a/libide/ide-source-view.c
+++ b/libide/ide-source-view.c
@@ -235,6 +235,8 @@ get_rect_for_iters (GtkTextView *text_view,
{
GdkRectangle area;
GdkRectangle tmp;
+ GtkTextIter begin;
+ GtkTextIter end;
GtkTextIter iter;
g_assert (GTK_IS_TEXT_VIEW (text_view));
@@ -242,12 +244,26 @@ get_rect_for_iters (GtkTextView *text_view,
g_assert (iter2);
g_assert (rect);
- gtk_text_view_get_iter_location (text_view, iter1, &area);
+ begin = *iter1;
+ end = *iter2;
+
+ gtk_text_iter_order (&begin, &end);
+
+ gtk_text_view_get_iter_location (text_view, &begin, &area);
- gtk_text_iter_assign (&iter, iter1);
+ if (gtk_text_iter_equal (&begin, &end))
+ goto finish;
+
+ iter = begin;
do
{
+ GtkTextIter peek = iter;
+
+ /* skip trailing newline */
+ if ((gtk_text_iter_starts_line (&iter) && gtk_text_iter_equal (&iter, &end)))
+ break;
+
gtk_text_view_get_iter_location (text_view, &iter, &tmp);
gdk_rectangle_union (&area, &tmp, &area);
@@ -258,8 +274,9 @@ get_rect_for_iters (GtkTextView *text_view,
if (!gtk_text_iter_forward_char (&iter))
break;
}
- while (gtk_text_iter_compare (&iter, iter2) <= 0);
+ while (gtk_text_iter_compare (&iter, &end) <= 0);
+finish:
gtk_text_view_buffer_to_window_coords (text_view, window_type, area.x, area.y, &area.x, &area.y);
*rect = area;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]