[gedit] When searching get the right iter as first iter when there is a selection



commit 9f358290fa28c6853073654d212fd29f3924850b
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Thu Apr 7 15:03:18 2011 +0200

    When searching get the right iter as first iter when there is a selection

 gedit/gedit-view-frame.c |   23 ++++++++++++++++++++---
 1 files changed, 20 insertions(+), 3 deletions(-)
---
diff --git a/gedit/gedit-view-frame.c b/gedit/gedit-view-frame.c
index 72c83f1..1b673d6 100644
--- a/gedit/gedit-view-frame.c
+++ b/gedit/gedit-view-frame.c
@@ -1288,8 +1288,8 @@ static void
 start_interactive_search_real (GeditViewFrame *frame)
 {
 	GtkTextBuffer *buffer;
-	GtkTextMark *mark;
 	GtkTextIter iter;
+	GtkTextMark *mark;
 
 	if (gtk_widget_get_visible (frame->priv->slider))
 	{
@@ -1309,14 +1309,31 @@ start_interactive_search_real (GeditViewFrame *frame)
 
 	if (frame->priv->search_mode == SEARCH)
 	{
-		mark = gtk_text_buffer_get_selection_bound (buffer);
+		GtkTextIter start, end;
+
+		if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
+		{
+			if (gtk_text_iter_compare (&start, &end) == -1)
+			{
+				iter = start;
+			}
+			else
+			{
+				iter = end;
+			}
+		}
+		else
+		{
+			mark = gtk_text_buffer_get_selection_bound (buffer);
+			gtk_text_buffer_get_iter_at_mark (buffer, &iter, mark);
+		}
 	}
 	else
 	{
 		mark = gtk_text_buffer_get_insert (buffer);
+		gtk_text_buffer_get_iter_at_mark (buffer, &iter, mark);
 	}
 
-	gtk_text_buffer_get_iter_at_mark (buffer, &iter, mark);
 	frame->priv->start_mark = gtk_text_buffer_create_mark (buffer, NULL,
 	                                                       &iter, FALSE);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]