[gtksourceview/wip/search: 14/36] forward/backward search: NULL for the end/start of the selection



commit 60faa135471935a7f5a79c6a4eb4b0c00eb3c2aa
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Jul 1 15:10:32 2013 +0200

    forward/backward search: NULL for the end/start of the selection

 gtksourceview/gtksourcebuffer.c |    8 +++-
 gtksourceview/gtksourcesearch.c |   66 +++++++++++++++++++++++++++++++++------
 2 files changed, 62 insertions(+), 12 deletions(-)
---
diff --git a/gtksourceview/gtksourcebuffer.c b/gtksourceview/gtksourcebuffer.c
index 7e951d9..aa42dd5 100644
--- a/gtksourceview/gtksourcebuffer.c
+++ b/gtksourceview/gtksourcebuffer.c
@@ -2773,12 +2773,14 @@ gtk_source_buffer_get_search_wrap_around (GtkSourceBuffer *buffer)
 /**
  * gtk_source_buffer_forward_search:
  * @buffer: a #GtkSourceBuffer.
- * @iter: start of search.
+ * @iter: start of search, or %NULL.
  * @match_start: return location for start of match, or %NULL.
  * @match_end: return location for end of match, or %NULL.
  *
  * Synchronous forward search.
  *
+ * If @iter is %NULL, the search begins at the end of the buffer selection.
+ *
  * Returns: whether a match was found.
  */
 gboolean
@@ -2830,12 +2832,14 @@ gtk_source_buffer_forward_search_finish (GtkSourceBuffer  *buffer,
 /**
  * gtk_source_buffer_backward_search:
  * @buffer: a #GtkSourceBuffer.
- * @iter: start of search.
+ * @iter: start of search, or %NULL.
  * @match_start: return location for start of match, or %NULL.
  * @match_end: return location for end of match, or %NULL.
  *
  * Synchronous backward search.
  *
+ * If @iter is %NULL, the search begins at the start of the buffer selection.
+ *
  * Returns: whether a match was found.
  */
 gboolean
diff --git a/gtksourceview/gtksourcesearch.c b/gtksourceview/gtksourcesearch.c
index 6c2d683..e91fffe 100644
--- a/gtksourceview/gtksourcesearch.c
+++ b/gtksourceview/gtksourcesearch.c
@@ -1710,18 +1710,29 @@ _gtk_source_search_forward (GtkSourceSearch   *search,
                            GtkTextIter       *match_start,
                            GtkTextIter       *match_end)
 {
+       GtkTextIter start_at;
        gboolean found;
 
        g_return_val_if_fail (GTK_SOURCE_IS_SEARCH (search), FALSE);
 
-       found = smart_forward_search (search, iter, match_start, match_end);
+       if (iter != NULL)
+       {
+               start_at = *iter;
+       }
+       else
+       {
+               gtk_text_buffer_get_selection_bounds (search->priv->buffer,
+                                                     NULL,
+                                                     &start_at);
+       }
+
+       found = smart_forward_search (search, &start_at, match_start, match_end);
 
        if (!found && search->priv->wrap_around)
        {
-               GtkTextIter start_iter;
-               gtk_text_buffer_get_start_iter (search->priv->buffer, &start_iter);
+               gtk_text_buffer_get_start_iter (search->priv->buffer, &start_at);
 
-               found = smart_forward_search (search, &start_iter, match_start, match_end);
+               found = smart_forward_search (search, &start_at, match_start, match_end);
        }
 
        return found;
@@ -1735,12 +1746,24 @@ _gtk_source_search_forward_async (GtkSourceSearch     *search,
                                  gpointer             user_data)
 {
        GTask *task;
+       GtkTextIter start_at;
 
        g_return_if_fail (GTK_SOURCE_IS_SEARCH (search));
 
        task = g_task_new (search->priv->buffer, cancellable, callback, user_data);
 
-       smart_forward_search_async (search, iter, task, FALSE);
+       if (iter != NULL)
+       {
+               start_at = *iter;
+       }
+       else
+       {
+               gtk_text_buffer_get_selection_bounds (search->priv->buffer,
+                                                     NULL,
+                                                     &start_at);
+       }
+
+       smart_forward_search_async (search, &start_at, task, FALSE);
 }
 
 gboolean
@@ -1788,18 +1811,29 @@ _gtk_source_search_backward (GtkSourceSearch   *search,
                             GtkTextIter       *match_start,
                             GtkTextIter       *match_end)
 {
+       GtkTextIter start_at;
        gboolean found;
 
        g_return_val_if_fail (GTK_SOURCE_IS_SEARCH (search), FALSE);
 
-       found = smart_backward_search (search, iter, match_start, match_end);
+       if (iter != NULL)
+       {
+               start_at = *iter;
+       }
+       else
+       {
+               gtk_text_buffer_get_selection_bounds (search->priv->buffer,
+                                                     &start_at,
+                                                     NULL);
+       }
+
+       found = smart_backward_search (search, &start_at, match_start, match_end);
 
        if (!found && search->priv->wrap_around)
        {
-               GtkTextIter end_iter;
-               gtk_text_buffer_get_end_iter (search->priv->buffer, &end_iter);
+               gtk_text_buffer_get_end_iter (search->priv->buffer, &start_at);
 
-               found = smart_backward_search (search, &end_iter, match_start, match_end);
+               found = smart_backward_search (search, &start_at, match_start, match_end);
        }
 
        return found;
@@ -1813,12 +1847,24 @@ _gtk_source_search_backward_async (GtkSourceSearch     *search,
                                   gpointer             user_data)
 {
        GTask *task;
+       GtkTextIter start_at;
 
        g_return_if_fail (GTK_SOURCE_IS_SEARCH (search));
 
        task = g_task_new (search->priv->buffer, cancellable, callback, user_data);
 
-       smart_backward_search_async (search, iter, task, FALSE);
+       if (iter != NULL)
+       {
+               start_at = *iter;
+       }
+       else
+       {
+               gtk_text_buffer_get_selection_bounds (search->priv->buffer,
+                                                     &start_at,
+                                                     NULL);
+       }
+
+       smart_backward_search_async (search, &start_at, task, FALSE);
 }
 
 gboolean



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