[gtksourceview/wip/chergert/vim] buffer: keep start and end valid across calls



commit 47609669cd5320cab3acef4f77f1a3e47e83be86
Author: Christian Hergert <chergert redhat com>
Date:   Tue Nov 2 13:49:28 2021 -0700

    buffer: keep start and end valid across calls
    
    To ensure that the caller can continue to use @start and @end, we need to
    update the text iters to surround the new text. This allows the caller to
    perform further modifications after changing the case.

 gtksourceview/gtksourcebuffer.c | 7 +++++++
 1 file changed, 7 insertions(+)
---
diff --git a/gtksourceview/gtksourcebuffer.c b/gtksourceview/gtksourcebuffer.c
index b7f8ce53..ae576739 100644
--- a/gtksourceview/gtksourcebuffer.c
+++ b/gtksourceview/gtksourcebuffer.c
@@ -2486,6 +2486,9 @@ do_title_case (GtkTextBuffer     *buffer,
  *
  * Changes the case of the text between the specified iterators.
  *
+ * Since 5.4, this function will update the position of @start and
+ * @end to surround the modified text.
+ *
  * Since: 3.12
  */
 void
@@ -2532,6 +2535,10 @@ gtk_source_buffer_change_case (GtkSourceBuffer         *buffer,
        gtk_text_buffer_insert (text_buffer, start, new_text, -1);
        gtk_text_buffer_end_user_action (text_buffer);
 
+        /* Leave @start and @end in valid positions around the text */
+       *end = *start;
+       gtk_text_iter_backward_chars (start, g_utf8_strlen (new_text, -1));
+
        g_free (new_text);
 }
 


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