]> Pileus Git - ~andy/gtk/commitdiff
fix test case, it previously verified incorrect behavior
authorHavoc Pennington <hp@redhat.com>
Thu, 4 Oct 2001 00:22:13 +0000 (00:22 +0000)
committerHavoc Pennington <hp@src.gnome.org>
Thu, 4 Oct 2001 00:22:13 +0000 (00:22 +0000)
2001-10-03  Havoc Pennington  <hp@redhat.com>

* tests/testtextbuffer.c (logical_motion_tests): fix test case,
it previously verified incorrect behavior

        Fixes for #61565

* gtk/gtktextiter.c (gtk_text_iter_set_line): don't return lines
off the end
(_gtk_text_btree_get_iter_at_line_char): don't return lines off
the end
(_gtk_text_btree_get_iter_at_line_byte): don't return lines off
the end
(gtk_text_iter_forward_lines): if on the last line, move to end of
it

* gtk/gtktextbtree.c (_gtk_text_btree_last_could_contain_tag):
don't return a line off the end

15 files changed:
ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
docs/reference/gtk/tmpl/gtk-unused.sgml
docs/reference/gtk/tmpl/gtkeditable.sgml
docs/reference/gtk/tmpl/gtkentry.sgml
docs/reference/gtk/tmpl/gtkoldeditable.sgml
gtk/gtktextbtree.c
gtk/gtktextbtree.h
gtk/gtktextiter.c
tests/testtextbuffer.c

index afe3d37a83a1ee9c79f6f63875787c7e1d7879e1..f901bdd679662f2c4a9b6fd6eb351d57537b7f21 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2001-10-03  Havoc Pennington  <hp@redhat.com>
+
+       * tests/testtextbuffer.c (logical_motion_tests): fix test case, 
+       it previously verified incorrect behavior
+
+        Fixes for #61565
+       
+       * gtk/gtktextiter.c (gtk_text_iter_set_line): don't return lines
+       off the end
+       (_gtk_text_btree_get_iter_at_line_char): don't return lines off
+       the end
+       (_gtk_text_btree_get_iter_at_line_byte): don't return lines off
+       the end
+       (gtk_text_iter_forward_lines): if on the last line, move to end of
+       it
+
+       * gtk/gtktextbtree.c (_gtk_text_btree_last_could_contain_tag):
+       don't return a line off the end
+
 Wed Oct  3 23:47:25  Kristian Rietveld  <kristian@planet.nl>
 
        * gtk/gtkeditable.[ch]: move insert_text and delete_text virtual
index afe3d37a83a1ee9c79f6f63875787c7e1d7879e1..f901bdd679662f2c4a9b6fd6eb351d57537b7f21 100644 (file)
@@ -1,3 +1,22 @@
+2001-10-03  Havoc Pennington  <hp@redhat.com>
+
+       * tests/testtextbuffer.c (logical_motion_tests): fix test case, 
+       it previously verified incorrect behavior
+
+        Fixes for #61565
+       
+       * gtk/gtktextiter.c (gtk_text_iter_set_line): don't return lines
+       off the end
+       (_gtk_text_btree_get_iter_at_line_char): don't return lines off
+       the end
+       (_gtk_text_btree_get_iter_at_line_byte): don't return lines off
+       the end
+       (gtk_text_iter_forward_lines): if on the last line, move to end of
+       it
+
+       * gtk/gtktextbtree.c (_gtk_text_btree_last_could_contain_tag):
+       don't return a line off the end
+
 Wed Oct  3 23:47:25  Kristian Rietveld  <kristian@planet.nl>
 
        * gtk/gtkeditable.[ch]: move insert_text and delete_text virtual
index afe3d37a83a1ee9c79f6f63875787c7e1d7879e1..f901bdd679662f2c4a9b6fd6eb351d57537b7f21 100644 (file)
@@ -1,3 +1,22 @@
+2001-10-03  Havoc Pennington  <hp@redhat.com>
+
+       * tests/testtextbuffer.c (logical_motion_tests): fix test case, 
+       it previously verified incorrect behavior
+
+        Fixes for #61565
+       
+       * gtk/gtktextiter.c (gtk_text_iter_set_line): don't return lines
+       off the end
+       (_gtk_text_btree_get_iter_at_line_char): don't return lines off
+       the end
+       (_gtk_text_btree_get_iter_at_line_byte): don't return lines off
+       the end
+       (gtk_text_iter_forward_lines): if on the last line, move to end of
+       it
+
+       * gtk/gtktextbtree.c (_gtk_text_btree_last_could_contain_tag):
+       don't return a line off the end
+
 Wed Oct  3 23:47:25  Kristian Rietveld  <kristian@planet.nl>
 
        * gtk/gtkeditable.[ch]: move insert_text and delete_text virtual
index afe3d37a83a1ee9c79f6f63875787c7e1d7879e1..f901bdd679662f2c4a9b6fd6eb351d57537b7f21 100644 (file)
@@ -1,3 +1,22 @@
+2001-10-03  Havoc Pennington  <hp@redhat.com>
+
+       * tests/testtextbuffer.c (logical_motion_tests): fix test case, 
+       it previously verified incorrect behavior
+
+        Fixes for #61565
+       
+       * gtk/gtktextiter.c (gtk_text_iter_set_line): don't return lines
+       off the end
+       (_gtk_text_btree_get_iter_at_line_char): don't return lines off
+       the end
+       (_gtk_text_btree_get_iter_at_line_byte): don't return lines off
+       the end
+       (gtk_text_iter_forward_lines): if on the last line, move to end of
+       it
+
+       * gtk/gtktextbtree.c (_gtk_text_btree_last_could_contain_tag):
+       don't return a line off the end
+
 Wed Oct  3 23:47:25  Kristian Rietveld  <kristian@planet.nl>
 
        * gtk/gtkeditable.[ch]: move insert_text and delete_text virtual
index afe3d37a83a1ee9c79f6f63875787c7e1d7879e1..f901bdd679662f2c4a9b6fd6eb351d57537b7f21 100644 (file)
@@ -1,3 +1,22 @@
+2001-10-03  Havoc Pennington  <hp@redhat.com>
+
+       * tests/testtextbuffer.c (logical_motion_tests): fix test case, 
+       it previously verified incorrect behavior
+
+        Fixes for #61565
+       
+       * gtk/gtktextiter.c (gtk_text_iter_set_line): don't return lines
+       off the end
+       (_gtk_text_btree_get_iter_at_line_char): don't return lines off
+       the end
+       (_gtk_text_btree_get_iter_at_line_byte): don't return lines off
+       the end
+       (gtk_text_iter_forward_lines): if on the last line, move to end of
+       it
+
+       * gtk/gtktextbtree.c (_gtk_text_btree_last_could_contain_tag):
+       don't return a line off the end
+
 Wed Oct  3 23:47:25  Kristian Rietveld  <kristian@planet.nl>
 
        * gtk/gtkeditable.[ch]: move insert_text and delete_text virtual
index afe3d37a83a1ee9c79f6f63875787c7e1d7879e1..f901bdd679662f2c4a9b6fd6eb351d57537b7f21 100644 (file)
@@ -1,3 +1,22 @@
+2001-10-03  Havoc Pennington  <hp@redhat.com>
+
+       * tests/testtextbuffer.c (logical_motion_tests): fix test case, 
+       it previously verified incorrect behavior
+
+        Fixes for #61565
+       
+       * gtk/gtktextiter.c (gtk_text_iter_set_line): don't return lines
+       off the end
+       (_gtk_text_btree_get_iter_at_line_char): don't return lines off
+       the end
+       (_gtk_text_btree_get_iter_at_line_byte): don't return lines off
+       the end
+       (gtk_text_iter_forward_lines): if on the last line, move to end of
+       it
+
+       * gtk/gtktextbtree.c (_gtk_text_btree_last_could_contain_tag):
+       don't return a line off the end
+
 Wed Oct  3 23:47:25  Kristian Rietveld  <kristian@planet.nl>
 
        * gtk/gtkeditable.[ch]: move insert_text and delete_text virtual
index afe3d37a83a1ee9c79f6f63875787c7e1d7879e1..f901bdd679662f2c4a9b6fd6eb351d57537b7f21 100644 (file)
@@ -1,3 +1,22 @@
+2001-10-03  Havoc Pennington  <hp@redhat.com>
+
+       * tests/testtextbuffer.c (logical_motion_tests): fix test case, 
+       it previously verified incorrect behavior
+
+        Fixes for #61565
+       
+       * gtk/gtktextiter.c (gtk_text_iter_set_line): don't return lines
+       off the end
+       (_gtk_text_btree_get_iter_at_line_char): don't return lines off
+       the end
+       (_gtk_text_btree_get_iter_at_line_byte): don't return lines off
+       the end
+       (gtk_text_iter_forward_lines): if on the last line, move to end of
+       it
+
+       * gtk/gtktextbtree.c (_gtk_text_btree_last_could_contain_tag):
+       don't return a line off the end
+
 Wed Oct  3 23:47:25  Kristian Rietveld  <kristian@planet.nl>
 
        * gtk/gtkeditable.[ch]: move insert_text and delete_text virtual
index a0b014f6279692d6b8640160d037b120aa55d8a8..3686e8751a2b3660995212dea6d8f1cbc29c1c25 100644 (file)
@@ -544,14 +544,6 @@ Control-Return for #GtkText.)
 
 @editable: the object which received the signal.
 
-<!-- ##### SIGNAL GtkEditable::changed ##### -->
-<para>
-Indicates that the user has changed the contents
-of the widget.
-</para>
-
-@editable: the object which received the signal.
-
 <!-- ##### SIGNAL GtkEditable::copy-clipboard ##### -->
 <para>
 An action signal. Causes the characters in the current selection to
@@ -569,42 +561,6 @@ the widget.
 
 @editable: the object which received the signal.
 
-<!-- ##### SIGNAL GtkEditable::delete-text ##### -->
-<para>
-This signal is emitted when text is deleted from
-the widget by the user. The default handler for
-this signal will normally be responsible for inserting
-the text, so by connecting to this signal and then
-stopping the signal with gtk_signal_emit_stop(), it
-is possible to modify the inserted text, or prevent
-it from being inserted entirely. The @start_pos
-and @end_pos parameters are interpreted as for
-gtk_editable_delete_text()
-</para>
-
-@editable: the object which received the signal.
-@start_pos: the starting position.
-@end_pos: the end position.
-
-<!-- ##### SIGNAL GtkEditable::insert-text ##### -->
-<para>
-This signal is emitted when text is inserted into
-the widget by the user. The default handler for
-this signal will normally be responsible for inserting
-the text, so by connecting to this signal and then
-stopping the signal with gtk_signal_emit_stop(), it
-is possible to modify the inserted text, or prevent
-it from being inserted entirely.
-</para>
-
-@editable: the object which received the signal.
-@new_text: the new text to insert.
-@new_text_length: the length of the new text.
-@position: the position at which to insert the new text.
-           this is an in-out paramter. After the signal
-           emission is finished, it should point after   
-           the newly inserted text.
-
 <!-- ##### SIGNAL GtkEditable::kill-char ##### -->
 <para>
 An action signal. Delete a single character.
@@ -729,6 +685,32 @@ You may not attach these to signals created with the
 @data: 
 @Returns: 
 
+<!-- ##### SIGNAL GtkEntry::changed ##### -->
+<para>
+
+</para>
+
+@entry: the object which received the signal.
+
+<!-- ##### SIGNAL GtkEntry::delete-text ##### -->
+<para>
+
+</para>
+
+@entry: the object which received the signal.
+@arg1: 
+@arg2: 
+
+<!-- ##### SIGNAL GtkEntry::insert-text ##### -->
+<para>
+
+</para>
+
+@entry: the object which received the signal.
+@arg1: 
+@arg2: 
+@arg3: 
+
 <!-- ##### ENUM GtkFontFilterType ##### -->
 <para>
 A set of bit flags used to specify the filter being set
@@ -835,6 +817,32 @@ after other user handlers and the default handler.
 </para>
 
 
+<!-- ##### SIGNAL GtkOldEditable::changed ##### -->
+<para>
+
+</para>
+
+@oldeditable: the object which received the signal.
+
+<!-- ##### SIGNAL GtkOldEditable::delete-text ##### -->
+<para>
+
+</para>
+
+@oldeditable: the object which received the signal.
+@arg1: 
+@arg2: 
+
+<!-- ##### SIGNAL GtkOldEditable::insert-text ##### -->
+<para>
+
+</para>
+
+@oldeditable: the object which received the signal.
+@arg1: 
+@arg2: 
+@arg3: 
+
 <!-- ##### ARG GtkPacker:default-border-width ##### -->
 <para>
 
index 399aad691542d107410a9077a0796cbeabdfff22..05238afeea91caffcd9cfd104d328674fffb3828 100644 (file)
@@ -252,3 +252,47 @@ widget or not.
 @Returns: 
 
 
+<!-- ##### SIGNAL GtkEditable::changed ##### -->
+<para>
+Indicates that the user has changed the contents
+of the widget.
+</para>
+
+@editable: the object which received the signal.
+
+<!-- ##### SIGNAL GtkEditable::delete-text ##### -->
+<para>
+This signal is emitted when text is deleted from
+the widget by the user. The default handler for
+this signal will normally be responsible for inserting
+the text, so by connecting to this signal and then
+stopping the signal with gtk_signal_emit_stop(), it
+is possible to modify the inserted text, or prevent
+it from being inserted entirely. The @start_pos
+and @end_pos parameters are interpreted as for
+gtk_editable_delete_text()
+</para>
+
+@editable: the object which received the signal.
+@start_pos: the starting position.
+@end_pos: the end position.
+
+<!-- ##### SIGNAL GtkEditable::insert-text ##### -->
+<para>
+This signal is emitted when text is inserted into
+the widget by the user. The default handler for
+this signal will normally be responsible for inserting
+the text, so by connecting to this signal and then
+stopping the signal with gtk_signal_emit_stop(), it
+is possible to modify the inserted text, or prevent
+it from being inserted entirely.
+</para>
+
+@editable: the object which received the signal.
+@new_text: the new text to insert.
+@new_text_length: the length of the new text.
+@position: the position at which to insert the new text.
+           this is an in-out paramter. After the signal
+           emission is finished, it should point after   
+           the newly inserted text.
+
index a461020b53376e0ba89e322651984f23541d5101..070fb1e231815851ac38c672f4b3ece627ae02c1 100644 (file)
@@ -287,13 +287,6 @@ to fit.
 
 @entry: the object which received the signal.
 
-<!-- ##### SIGNAL GtkEntry::changed ##### -->
-<para>
-
-</para>
-
-@entry: the object which received the signal.
-
 <!-- ##### SIGNAL GtkEntry::copy-clipboard ##### -->
 <para>
 
@@ -317,15 +310,6 @@ to fit.
 @arg1: 
 @arg2: 
 
-<!-- ##### SIGNAL GtkEntry::delete-text ##### -->
-<para>
-
-</para>
-
-@entry: the object which received the signal.
-@arg1: 
-@arg2: 
-
 <!-- ##### SIGNAL GtkEntry::insert-at-cursor ##### -->
 <para>
 
@@ -334,16 +318,6 @@ to fit.
 @entry: the object which received the signal.
 @arg1: 
 
-<!-- ##### SIGNAL GtkEntry::insert-text ##### -->
-<para>
-
-</para>
-
-@entry: the object which received the signal.
-@arg1: 
-@arg2: 
-@arg3: 
-
 <!-- ##### SIGNAL GtkEntry::move-cursor ##### -->
 <para>
 
index c59280ccfca087aaaf1849eccf4b46c75027ebf3..2f0580157fb1ab2d8b5f0e3639ca5ab4e7fbb617 100644 (file)
@@ -58,13 +58,6 @@ GtkOldEditable
 
 @oldeditable: the object which received the signal.
 
-<!-- ##### SIGNAL GtkOldEditable::changed ##### -->
-<para>
-
-</para>
-
-@oldeditable: the object which received the signal.
-
 <!-- ##### SIGNAL GtkOldEditable::copy-clipboard ##### -->
 <para>
 
@@ -79,25 +72,6 @@ GtkOldEditable
 
 @oldeditable: the object which received the signal.
 
-<!-- ##### SIGNAL GtkOldEditable::delete-text ##### -->
-<para>
-
-</para>
-
-@oldeditable: the object which received the signal.
-@arg1: 
-@arg2: 
-
-<!-- ##### SIGNAL GtkOldEditable::insert-text ##### -->
-<para>
-
-</para>
-
-@oldeditable: the object which received the signal.
-@arg1: 
-@arg2: 
-@arg3: 
-
 <!-- ##### SIGNAL GtkOldEditable::kill-char ##### -->
 <para>
 
index 8402b2508e5a2c9b3427fc7e8fe124725f667581..3659538960e03292e0d79b023aded3c208927417 100644 (file)
@@ -1854,10 +1854,11 @@ _gtk_text_btree_tag (const GtkTextIter *start_orig,
  * "Getters"
  */
 
-GtkTextLine*
-_gtk_text_btree_get_line (GtkTextBTree *tree,
-                         gint  line_number,
-                         gint *real_line_number)
+static GtkTextLine*
+get_line_internal (GtkTextBTree *tree,
+                   gint          line_number,
+                   gint         *real_line_number,
+                   gboolean      include_last)
 {
   GtkTextBTreeNode *node;
   GtkTextLine *line;
@@ -1865,7 +1866,9 @@ _gtk_text_btree_get_line (GtkTextBTree *tree,
   int line_count;
 
   line_count = _gtk_text_btree_line_count (tree);
-
+  if (!include_last)
+    line_count -= 1;
+  
   if (line_number < 0)
     {
       line_number = line_count;
@@ -1929,6 +1932,22 @@ _gtk_text_btree_get_end_iter_line (GtkTextBTree *tree)
                               NULL);
 }
 
+GtkTextLine*
+_gtk_text_btree_get_line (GtkTextBTree *tree,
+                          gint          line_number,
+                          gint         *real_line_number)
+{
+  return get_line_internal (tree, line_number, real_line_number, TRUE);
+}
+
+GtkTextLine*
+_gtk_text_btree_get_line_no_last (GtkTextBTree      *tree,
+                                  gint               line_number,
+                                  gint              *real_line_number)
+{
+  return get_line_internal (tree, line_number, real_line_number, FALSE);
+}
+
 GtkTextLine*
 _gtk_text_btree_get_line_at_char (GtkTextBTree      *tree,
                                   gint               char_index,
@@ -2919,7 +2938,7 @@ _gtk_text_btree_last_could_contain_tag (GtkTextBTree *tree,
          at least not without complexity.
          So, we just return the last line.
       */
-      return _gtk_text_btree_get_line (tree, -1, NULL);
+      return _gtk_text_btree_get_end_iter_line (tree);
     }
 }
 
@@ -3181,7 +3200,7 @@ ensure_end_iter_line (GtkTextBTree *tree)
  
       g_assert (n_lines >= 1);
 
-      tree->end_iter_line = _gtk_text_btree_get_line (tree, n_lines - 1, &real_line);
+      tree->end_iter_line = _gtk_text_btree_get_line_no_last (tree, -1, &real_line);
       
       tree->end_iter_line_stamp = tree->chars_changed_stamp;
     }
index b3434ff4d6d0513bfa81786c2ffc58b8feb6b254..2736fa6988bf56e2dcb92d4ce6ff1832efb43f98 100644 (file)
@@ -87,6 +87,9 @@ void _gtk_text_btree_tag (const GtkTextIter *start,
 GtkTextLine * _gtk_text_btree_get_line          (GtkTextBTree      *tree,
                                                  gint               line_number,
                                                  gint              *real_line_number);
+GtkTextLine * _gtk_text_btree_get_line_no_last  (GtkTextBTree      *tree,
+                                                 gint               line_number,
+                                                 gint              *real_line_number);
 GtkTextLine * _gtk_text_btree_get_end_iter_line (GtkTextBTree      *tree);
 GtkTextLine * _gtk_text_btree_get_line_at_char  (GtkTextBTree      *tree,
                                                  gint               char_index,
index 62cbde55b523008cf9af77d39204b7c6037bb152..1b8fbf9317797677d18a015372ec9f40f70c9e2e 100644 (file)
@@ -2569,7 +2569,7 @@ gtk_text_iter_backward_line (GtkTextIter *iter)
   /* Find first segment in line */
   real->any_segment = real->line->segments;
   real->segment = _gtk_text_line_byte_to_segment (real->line,
-                                                 0, &offset);
+                                                  0, &offset);
 
   g_assert (offset == 0);
 
@@ -2618,16 +2618,21 @@ gtk_text_iter_forward_lines (GtkTextIter *iter, gint count)
     {
       gint old_line;
 
+      if (gtk_text_iter_is_end (iter))
+        return FALSE;
+      
       old_line = gtk_text_iter_get_line (iter);
 
       gtk_text_iter_set_line (iter, old_line + count);
 
-      check_invariants (iter);
-
-      /* return whether it moved, and is dereferenceable. */
-      return
-        (gtk_text_iter_get_line (iter) != old_line) &&
-        !gtk_text_iter_is_end (iter);
+      if ((gtk_text_iter_get_line (iter) - old_line) < count)
+        {
+          /* count went past the last line, so move to end of last line */
+          if (!gtk_text_iter_is_end (iter))
+            gtk_text_iter_forward_to_end (iter);
+        }
+      
+      return !gtk_text_iter_is_end (iter);
     }
 }
 
@@ -3647,7 +3652,7 @@ gtk_text_iter_set_line (GtkTextIter *iter,
 
   check_invariants (iter);
 
-  line = _gtk_text_btree_get_line (real->tree, line_number, &real_line);
+  line = _gtk_text_btree_get_line_no_last (real->tree, line_number, &real_line);
 
   iter_set_from_char_offset (real, line, 0);
 
@@ -4887,7 +4892,7 @@ _gtk_text_btree_get_iter_at_char (GtkTextBTree *tree,
   g_return_if_fail (tree != NULL);
 
   line = _gtk_text_btree_get_line_at_char (tree, char_index,
-                                          &line_start, &real_char_index);
+                                           &line_start, &real_char_index);
 
   iter_init_from_char_offset (iter, tree, line, real_char_index - line_start);
 
@@ -4898,9 +4903,9 @@ _gtk_text_btree_get_iter_at_char (GtkTextBTree *tree,
 
 void
 _gtk_text_btree_get_iter_at_line_char (GtkTextBTree *tree,
-                                       GtkTextIter *iter,
-                                       gint line_number,
-                                       gint char_on_line)
+                                       GtkTextIter  *iter,
+                                       gint          line_number,
+                                       gint          char_on_line)
 {
   GtkTextRealIter *real = (GtkTextRealIter*)iter;
   GtkTextLine *line;
@@ -4909,7 +4914,7 @@ _gtk_text_btree_get_iter_at_line_char (GtkTextBTree *tree,
   g_return_if_fail (iter != NULL);
   g_return_if_fail (tree != NULL);
 
-  line = _gtk_text_btree_get_line (tree, line_number, &real_line);
+  line = _gtk_text_btree_get_line_no_last (tree, line_number, &real_line);
   
   iter_init_from_char_offset (iter, tree, line, char_on_line);
 
@@ -4932,7 +4937,7 @@ _gtk_text_btree_get_iter_at_line_byte (GtkTextBTree   *tree,
   g_return_if_fail (iter != NULL);
   g_return_if_fail (tree != NULL);
 
-  line = _gtk_text_btree_get_line (tree, line_number, &real_line);
+  line = _gtk_text_btree_get_line_no_last (tree, line_number, &real_line);
 
   iter_init_from_byte_offset (iter, tree, line, byte_index);
 
index 175deb9857f97547a9f4896caaad5b1e1de2b22a..0e29a0768f6e0c115214bc57cd498fbafdcbe078 100644 (file)
@@ -1039,9 +1039,9 @@ logical_motion_tests (void)
   memset (expected, 0, sizeof (expected));
 
   expected[0] = 24;
-  expected[1] = 22;
+  expected[1] = 21;
   expected[2] = 17;
-  expected[3] = 14;
+  expected[3] = 13;
   expected[4] = 9;
   expected[5] = 4;
   expected[6] = 0;