[gtksourceview] SearchContext: fix bug replace when regex + at word boundaries
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] SearchContext: fix bug replace when regex + at word boundaries
- Date: Fri, 2 Jan 2015 20:20:45 +0000 (UTC)
commit 2171a6ec5fcb53f9f387125ce55d96e595bb667f
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Jan 2 20:54:20 2015 +0100
SearchContext: fix bug replace when regex + at word boundaries
https://bugzilla.gnome.org/show_bug.cgi?id=740810
gtksourceview/gtksourcesearchcontext.c | 2 +-
tests/test-search-context.c | 21 ++++++++++++++++++++-
2 files changed, 21 insertions(+), 2 deletions(-)
---
diff --git a/gtksourceview/gtksourcesearchcontext.c b/gtksourceview/gtksourcesearchcontext.c
index b769b5c..4c6c245 100644
--- a/gtksourceview/gtksourcesearchcontext.c
+++ b/gtksourceview/gtksourcesearchcontext.c
@@ -3528,7 +3528,7 @@ regex_replace (GtkSourceSearchContext *search,
gtk_text_buffer_begin_user_action (search->priv->buffer);
gtk_text_buffer_delete (search->priv->buffer, match_start, match_end);
- gtk_text_buffer_insert (search->priv->buffer, match_end, subject_replaced, -1);
+ gtk_text_buffer_insert (search->priv->buffer, match_end, subject_replaced + start_pos, -1);
gtk_text_buffer_end_user_action (search->priv->buffer);
g_free (subject_replaced);
diff --git a/tests/test-search-context.c b/tests/test-search-context.c
index 71ece13..daa1678 100644
--- a/tests/test-search-context.c
+++ b/tests/test-search-context.c
@@ -2,7 +2,7 @@
* test-search-context.c
* This file is part of GtkSourceView
*
- * Copyright (C) 2013 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2013, 2015 - Sébastien Wilmet <swilmet gnome org>
*
* GtkSourceView is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -994,7 +994,10 @@ test_regex_at_word_boundaries (void)
GtkTextIter iter;
GtkTextIter match_start;
GtkTextIter match_end;
+ GtkTextIter start;
+ GtkTextIter end;
gint offset;
+ gchar *content;
gtk_text_buffer_set_text (text_buffer, "1234\n12345\n1234", -1);
@@ -1019,6 +1022,22 @@ test_regex_at_word_boundaries (void)
offset = gtk_text_iter_get_offset (&match_end);
g_assert_cmpint (offset, ==, 15);
+ /* Test replace, see https://bugzilla.gnome.org/show_bug.cgi?id=740810 */
+
+ gtk_text_buffer_set_text (text_buffer, "&aa", -1);
+ gtk_source_search_settings_set_search_text (settings, "aa");
+ flush_queue ();
+
+ gtk_text_buffer_get_iter_at_offset (text_buffer, &match_start, 1);
+ gtk_text_buffer_get_end_iter (text_buffer, &match_end);
+ gtk_source_search_context_replace (context, &match_start, &match_end, "bb", -1, NULL);
+
+ gtk_text_buffer_get_start_iter (text_buffer, &start);
+ gtk_text_buffer_get_end_iter (text_buffer, &end);
+ content = gtk_text_iter_get_visible_text (&start, &end);
+ g_assert_cmpstr (content, ==, "&bb");
+ g_free (content);
+
g_object_unref (source_buffer);
g_object_unref (settings);
g_object_unref (context);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]