Tk Source Code

Artifact [2120b8be33]
Login

Artifact 2120b8be333171f99dd9111b7a3efd67b3554a15:

Attachment "3021557_V1.patch" to ticket [3472539fff] added by fvogelnew1 2012-01-12 03:29:48.
Index: generic/tkText.c
==================================================================
--- generic/tkText.c
+++ generic/tkText.c
@@ -918,31 +918,24 @@
 
 		/*
 		 * We're going to count up all display lines in the logical
 		 * line of 'indexFromPtr' up to, but not including the logical
 		 * line of 'indexToPtr', and then subtract off what we didn't
-		 * what from 'from' and add on what we didn't count from 'to.
+		 * want from 'from' and add on what we didn't count from 'to.
 		 */
 
 		while (index.linePtr != indexToPtr->linePtr) {
 		    value += TkTextUpdateOneLine(textPtr, fromPtr,0,&index,0);
 
 		    /*
 		     * We might have skipped past indexToPtr, if we have
 		     * multiple logical lines in a single display line.
-		     * Therefore we iterate through each intermediate logical
-		     * line, just to check. Another approach would be just to
-		     * use TkTextIndexCmp on every while() iteration, but that
-		     * would be less efficient.
 		     */
 
-		    while (fromPtr != index.linePtr) {
-			fromPtr = TkBTreeNextLine(textPtr, fromPtr);
-			if (fromPtr == indexToPtr->linePtr) {
-			    break;
-			}
-		    }
+                    if (TkTextIndexCmp(&index,indexToPtr) > 0) {
+                        break;
+                    }
 		}
 
 		/*
 		 * Now we need to adjust the count to add on the number of
 		 * display lines in the last logical line, and subtract off

Index: tests/text.test
==================================================================
--- tests/text.test
+++ tests/text.test
@@ -2613,10 +2613,28 @@
     .t insert end [string repeat "klmno " 50]
     .t count -lines -chars -indices -displaylines 1.0 end
 } -cleanup {
     destroy .t
 } -result {3 903 903 45}
+test text-10.39 {TextWidgetCmd procedure, "count" option} -setup {
+    text .t
+    pack .t
+    update
+    set res {}
+} -body {
+    .t insert end "Line 1 - This is Line 1\n"
+    .t insert end "Line 2 - This is Line 2\n"
+    .t insert end "Line 3 - This is Line 3\n"
+    .t insert end "Line 4 - This is Line 4\n"
+    .t insert end "Line 5 - This is Line 5\n"
+    lappend res [.t count -displaylines 1.19 3.24] [.t count -displaylines 1.0 end]
+    .t tag add hidden 2.9 3.17
+    .t tag configure hidden -elide true
+    lappend res [.t count -displaylines 1.19 3.24] [.t count -displaylines 1.0 end]
+} -cleanup {
+    destroy .t
+} -result {2 6 2 5}
 
 
 test text-11.1 {counting with tag priority eliding} -setup {
     text .t -font {Courier -12} -borderwidth 2 -highlightthickness 2
     pack append . .t {top expand fill}