[gtk+] Simplify _gtk_text_buffer_get_line_log_attrs()
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Simplify _gtk_text_buffer_get_line_log_attrs()
- Date: Thu, 21 Aug 2014 16:49:04 +0000 (UTC)
commit 706c8e9c8d29a93fabc1d787894827b709139b6e
Author: Sébastien Wilmet <swilmet gnome org>
Date: Wed Aug 20 19:06:05 2014 +0200
Simplify _gtk_text_buffer_get_line_log_attrs()
NULL was returned in case of an empty last line. Every users needed to
special-case this. Now it will return the expected result: char_len of 0
with one PangoLogAttr.
In compute_log_attrs(), 'paragraph' will be the empty string "" with
'char_len' == 0.
pango_get_log_attrs() works fine with an empty string, it will return
one correct PangoLogAttr (because there is one text position for the
empty string).
It fixes the unit tests for gtk_text_iter_is_cursor_position().
https://bugzilla.gnome.org/show_bug.cgi?id=156164
gtk/gtktextbuffer.c | 26 ++++----------------------
gtk/gtktextiter.c | 26 +++++++-------------------
testsuite/gtk/textiter.c | 4 ++--
3 files changed, 13 insertions(+), 43 deletions(-)
---
diff --git a/gtk/gtktextbuffer.c b/gtk/gtktextbuffer.c
index 38620ef..65dfd85 100644
--- a/gtk/gtktextbuffer.c
+++ b/gtk/gtktextbuffer.c
@@ -3889,6 +3889,7 @@ gtk_text_buffer_backspace (GtkTextBuffer *buffer,
GtkTextIter end;
gboolean retval = FALSE;
const PangoLogAttr *attrs;
+ gint offset;
gboolean backspace_deletes_character;
g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), FALSE);
@@ -3898,17 +3899,8 @@ gtk_text_buffer_backspace (GtkTextBuffer *buffer,
end = *iter;
attrs = _gtk_text_buffer_get_line_log_attrs (buffer, &start, NULL);
-
- /* For no good reason, attrs is NULL for the empty last line in
- * a buffer. Special case that here. (#156164)
- */
- if (attrs != NULL)
- {
- gint offset = gtk_text_iter_get_line_offset (&start);
- backspace_deletes_character = attrs[offset].backspace_deletes_character;
- }
- else
- backspace_deletes_character = FALSE;
+ offset = gtk_text_iter_get_line_offset (&start);
+ backspace_deletes_character = attrs[offset].backspace_deletes_character;
gtk_text_iter_backward_cursor_position (&start);
@@ -4325,8 +4317,6 @@ compute_log_attrs (const GtkTextIter *iter,
char_len = g_utf8_strlen (paragraph, -1);
byte_len = strlen (paragraph);
- g_assert (char_len > 0);
-
if (char_lenp != NULL)
*char_lenp = char_len;
@@ -4346,6 +4336,7 @@ compute_log_attrs (const GtkTextIter *iter,
}
/* The return value from this is valid until you call this a second time.
+ * Returns (char_len + 1) PangoLogAttr's, one for each text position.
*/
const PangoLogAttr *
_gtk_text_buffer_get_line_log_attrs (GtkTextBuffer *buffer,
@@ -4362,15 +4353,6 @@ _gtk_text_buffer_get_line_log_attrs (GtkTextBuffer *buffer,
priv = buffer->priv;
- /* special-case for empty last line in buffer */
- if (gtk_text_iter_is_end (anywhere_in_line) &&
- gtk_text_iter_get_line_offset (anywhere_in_line) == 0)
- {
- if (char_len != NULL)
- *char_len = 0;
- return NULL;
- }
-
/* FIXME we also need to recompute log attrs if the language tag at
* the start of a paragraph changes
*/
diff --git a/gtk/gtktextiter.c b/gtk/gtktextiter.c
index 7b58cb4..38cb175 100644
--- a/gtk/gtktextiter.c
+++ b/gtk/gtktextiter.c
@@ -3060,7 +3060,6 @@ test_log_attrs (const GtkTextIter *iter,
gint char_len;
const PangoLogAttr *attrs;
gint offset;
- gboolean result = FALSE;
g_return_val_if_fail (iter != NULL, FALSE);
@@ -3069,16 +3068,9 @@ test_log_attrs (const GtkTextIter *iter,
offset = gtk_text_iter_get_line_offset (iter);
- /* char_len may be 0 and attrs will be NULL if so, if
- * iter is the end iter and the last line is empty.
- *
- * offset may be equal to char_len, since attrs contains an entry
- * for one past the end.
- */
- if (attrs != NULL && offset <= char_len)
- result = (* func) (attrs, offset, 0, char_len);
+ g_assert (offset <= char_len);
- return result;
+ return (* func) (attrs, offset, 0, char_len);
}
static gboolean
@@ -3090,7 +3082,6 @@ find_line_log_attrs (const GtkTextIter *iter,
gint char_len;
const PangoLogAttr *attrs;
gint offset;
- gboolean result = FALSE;
g_return_val_if_fail (iter != NULL, FALSE);
@@ -3098,15 +3089,12 @@ find_line_log_attrs (const GtkTextIter *iter,
iter, &char_len);
offset = gtk_text_iter_get_line_offset (iter);
-
- /* char_len may be 0 and attrs will be NULL if so, if
- * iter is the end iter and the last line is empty.
- */
- if (attrs != NULL)
- result = (* func) (attrs, offset, char_len, found_offset,
- already_moved_initially);
- return result;
+ return (* func) (attrs,
+ offset,
+ char_len,
+ found_offset,
+ already_moved_initially);
}
static gboolean
diff --git a/testsuite/gtk/textiter.c b/testsuite/gtk/textiter.c
index 21c1869..d05a897 100644
--- a/testsuite/gtk/textiter.c
+++ b/testsuite/gtk/textiter.c
@@ -538,8 +538,8 @@ test_cursor_positions (void)
check_is_cursor_position ("a\r\n", 0, TRUE);
check_is_cursor_position ("a\r\n", 1, TRUE);
check_is_cursor_position ("a\r\n", 2, FALSE);
- check_is_cursor_position ("a\r\n", 3, FALSE); /* FIXME should be TRUE */
- check_is_cursor_position ("", 0, FALSE); /* FIXME should be TRUE */
+ check_is_cursor_position ("a\r\n", 3, TRUE);
+ check_is_cursor_position ("", 0, TRUE);
/* forward */
check_cursor_position ("a\r\nb", TRUE, 0, 1, TRUE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]