[gtk+] buffer_backspace should delete \r\n in one go
- From: Matthias Clasen <matthiasc src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gtk+] buffer_backspace should delete \r\n in one go
- Date: Sun, 30 Aug 2009 01:32:00 +0000 (UTC)
commit 2d8b8e054a76901aa625725bac8b7610ff927a77
Author: Paolo Borelli <pborelli katamail com>
Date: Sat Aug 29 21:29:57 2009 -0400
buffer_backspace should delete \r\n in one go
Special case \r\n in gtk_text_buffer_backspace since \r should not be
reinserted even if we are deleting one char at a time. Also add
corresponding unit test. Fixes bug #544724.
gtk/gtktextbuffer.c | 5 +++--
gtk/tests/textbuffer.c | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 40 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtktextbuffer.c b/gtk/gtktextbuffer.c
index ceaa113..83039e3 100644
--- a/gtk/gtktextbuffer.c
+++ b/gtk/gtktextbuffer.c
@@ -3887,13 +3887,14 @@ gtk_text_buffer_backspace (GtkTextBuffer *buffer,
if (gtk_text_buffer_delete_interactive (buffer, &start, &end,
default_editable))
{
- if (backspace_deletes_character)
+ /* special case \r\n, since we never want to reinsert \r */
+ if (backspace_deletes_character && strcmp ("\r\n", cluster_text))
{
gchar *normalized_text = g_utf8_normalize (cluster_text,
strlen (cluster_text),
G_NORMALIZE_NFD);
glong len = g_utf8_strlen (normalized_text, -1);
-
+
if (len > 1)
gtk_text_buffer_insert_interactive (buffer,
&start,
diff --git a/gtk/tests/textbuffer.c b/gtk/tests/textbuffer.c
index 822b04c..010776d 100644
--- a/gtk/tests/textbuffer.c
+++ b/gtk/tests/textbuffer.c
@@ -879,6 +879,8 @@ split_r_n_separators_test (void)
gtk_text_buffer_get_iter_at_offset (buffer, &iter, 3);
g_assert (gtk_text_iter_ends_line (&iter));
+
+ g_object_unref (buffer);
}
static void
@@ -913,6 +915,40 @@ test_line_separator (void)
}
static void
+test_backspace (void)
+{
+ GtkTextBuffer *buffer;
+ GtkTextIter iter;
+ gboolean ret;
+
+ buffer = gtk_text_buffer_new (NULL);
+
+ gtk_text_buffer_set_text (buffer, "foo", -1);
+ gtk_text_buffer_get_iter_at_offset (buffer, &iter, 2);
+ ret = gtk_text_buffer_backspace (buffer, &iter, TRUE, TRUE);
+ g_assert (ret);
+ g_assert_cmpint (1, ==, gtk_text_iter_get_offset (&iter));
+ g_assert_cmpint (2, ==, gtk_text_buffer_get_char_count (buffer));
+
+ gtk_text_buffer_set_text (buffer, "foo", -1);
+ gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0);
+ ret = gtk_text_buffer_backspace (buffer, &iter, TRUE, TRUE);
+ g_assert (!ret);
+ g_assert_cmpint (0, ==, gtk_text_iter_get_offset (&iter));
+ g_assert_cmpint (3, ==, gtk_text_buffer_get_char_count (buffer));
+
+ /* test bug #544724 */
+ gtk_text_buffer_set_text (buffer, "foo\r\n\r\nbar", -1);
+ gtk_text_buffer_get_iter_at_offset (buffer, &iter, 5);
+ ret = gtk_text_buffer_backspace (buffer, &iter, TRUE, TRUE);
+ g_assert (ret);
+ g_assert_cmpint (0, ==, gtk_text_iter_get_line (&iter));
+ g_assert_cmpint (8, ==, gtk_text_buffer_get_char_count (buffer));
+
+ g_object_unref (buffer);
+}
+
+static void
test_logical_motion (void)
{
char *str;
@@ -1297,6 +1333,7 @@ main (int argc, char** argv)
g_test_add_func ("/TextBuffer/UTF8 unknown char", test_utf8);
g_test_add_func ("/TextBuffer/Line separator", test_line_separator);
+ g_test_add_func ("/TextBuffer/Backspace", test_backspace);
g_test_add_func ("/TextBuffer/Logical motion", test_logical_motion);
g_test_add_func ("/TextBuffer/Marks", test_marks);
g_test_add_func ("/TextBuffer/Empty buffer", test_empty_buffer);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]