summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfvogel <fvogelnew1@free.fr>2014-11-22 23:04:15 (GMT)
committerfvogel <fvogelnew1@free.fr>2014-11-22 23:04:15 (GMT)
commit567a2113a4b476c36f3c2a8ee85172ef7c361f65 (patch)
treeca63d8f48ef3de16403945b4f136ea53931a07d1
parent63bc8b0324a647da4fdb5618dd8b973ecf2aae87 (diff)
parent94831611278c36aeb3cea4a1e509446ead130ba9 (diff)
downloadtk-567a2113a4b476c36f3c2a8ee85172ef7c361f65.zip
tk-567a2113a4b476c36f3c2a8ee85172ef7c361f65.tar.gz
tk-567a2113a4b476c36f3c2a8ee85172ef7c361f65.tar.bz2
Merged from branch bug-c24b97d905
-rw-r--r--generic/tkText.c53
-rw-r--r--generic/tkTextDisp.c20
-rw-r--r--tests/text.test36
3 files changed, 79 insertions, 30 deletions
diff --git a/generic/tkText.c b/generic/tkText.c
index f3e1c26..1156086 100644
--- a/generic/tkText.c
+++ b/generic/tkText.c
@@ -871,7 +871,7 @@ TextWidgetObjCmd(
} else if (c == 'd' && (length > 8)
&& !strncmp("-displaylines", option, (unsigned) length)) {
TkTextLine *fromPtr, *lastPtr;
- TkTextIndex index;
+ TkTextIndex index, index2;
int compare = TkTextIndexCmp(indexFromPtr, indexToPtr);
value = 0;
@@ -906,35 +906,44 @@ TextWidgetObjCmd(
/*
* 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
- * want from 'from' and add on what we didn't count from 'to.
+ * line of 'indexToPtr' (except if this line is elided), and
+ * then subtract off what came in too much from elided lines,
+ * also subtract off we didn't 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.
- */
- if (TkTextIndexCmp(&index,indexToPtr) > 0) {
- break;
- }
+ while (TkTextIndexCmp(&index,indexToPtr) < 0) {
+ value += TkTextUpdateOneLine(textPtr, index.linePtr,
+ 0, &index, 0);
}
- /*
- * Now we need to adjust the count to add on the number of
- * display lines in the last logical line, and subtract off
- * the number of display lines overcounted in the first
- * logical line. This logic is still ok if both indices are in
- * the same logical line.
- */
+ index2 = index;
+
+ /*
+ * Now we need to adjust the count to:
+ * - subtract off the number of display lines between
+ * indexToPtr and index2, since we might have skipped past
+ * indexToPtr, if we have several logical lines in a
+ * single display line
+ * - subtract off the number of display lines overcounted
+ * in the first logical line
+ * - add on the number of display lines in the last logical
+ * line
+ * This logic is still ok if both indexFromPtr and indexToPtr
+ * are in the same logical line.
+ */
+ index = *indexToPtr;
+ index.byteIndex = 0;
+ while (TkTextIndexCmp(&index,&index2) < 0) {
+ value -= TkTextUpdateOneLine(textPtr, index.linePtr,
+ 0, &index, 0);
+ }
index.linePtr = indexFromPtr->linePtr;
index.byteIndex = 0;
while (1) {
TkTextFindDisplayLineEnd(textPtr, &index, 1, NULL);
- if (index.byteIndex >= indexFromPtr->byteIndex) {
+ if (TkTextIndexCmp(&index,indexFromPtr) >= 0) {
break;
}
TkTextIndexForwBytes(textPtr, &index, 1, &index);
@@ -946,7 +955,7 @@ TextWidgetObjCmd(
index.byteIndex = 0;
while (1) {
TkTextFindDisplayLineEnd(textPtr, &index, 1, NULL);
- if (index.byteIndex >= indexToPtr->byteIndex) {
+ if (TkTextIndexCmp(&index,indexToPtr) >= 0) {
break;
}
TkTextIndexForwBytes(textPtr, &index, 1, &index);
diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c
index f16c45b..510f3e0 100644
--- a/generic/tkTextDisp.c
+++ b/generic/tkTextDisp.c
@@ -3703,9 +3703,11 @@ TkTextUpdateOneLine(
/*
* Iterate through all display-lines corresponding to the single logical
- * line 'linePtr', adding up the pixel height of each such display line as
- * we go along. The final total is, therefore, the height of the logical
- * line.
+ * line 'linePtr' (and lines merged into this line due to eol elision),
+ * adding up the pixel height of each such display line as we go along.
+ * The final total is, therefore, the total height of all display lines
+ * made up by the logical line 'linePtr' and subsequent logical lines
+ * merged into this line.
*/
displayLines = 0;
@@ -3736,7 +3738,7 @@ TkTextUpdateOneLine(
break;
}
- if (logicalLines == 0) {
+ if (mergedLines == 0) {
if (indexPtr->linePtr != linePtr) {
/*
* If we reached the end of the logical line, then either way
@@ -3746,9 +3748,11 @@ TkTextUpdateOneLine(
partialCalc = 0;
break;
}
- } else if (indexPtr->byteIndex != 0) {
+ } else {
+ if (indexPtr->byteIndex != 0) {
/*
- * We must still be on the same wrapped line.
+ * We must still be on the same wrapped line, on a new logical
+ * line merged with the logical line 'linePtr'.
*/
} else {
/*
@@ -3771,9 +3775,11 @@ TkTextUpdateOneLine(
}
/*
- * We must still be on the same wrapped line.
+ * We must still be on the same wrapped line, on a new logical
+ * line merged with the logical line 'linePtr'.
*/
}
+ }
if (partialCalc && displayLines > 50 && mergedLines == 0) {
/*
* Only calculate 50 display lines at a time, to avoid huge
diff --git a/tests/text.test b/tests/text.test
index 52689ba..6121b85 100644
--- a/tests/text.test
+++ b/tests/text.test
@@ -698,7 +698,41 @@ test text-9.2.44 {TextWidgetCmd procedure, "count" option} -setup {
.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]
-} -result {2 6 2 5}
+} -result {2 6 1 5}
+test text-9.2.45 {TextWidgetCmd procedure, "count" option} -setup {
+ .t delete 1.0 end
+ update
+ set res {}
+} -body {
+ for {set i 1} {$i < 5} {incr i} {
+ .t insert end "Line $i+++Line $i---Line $i///Line $i - This is Line [format %c [expr 64+$i]]\n"
+ }
+ .t tag configure hidden -elide true
+ .t tag add hidden 2.15 3.10
+ .t configure -wrap none
+ set res [.t count -displaylines 2.0 3.0]
+} -result {0}
+test text-9.2.46 {TextWidgetCmd procedure, "count" option} -setup {
+ toplevel .mytop
+ pack [text .mytop.t]
+ wm geometry .mytop 100x300+0+0
+ .mytop.t delete 1.0 end
+ update
+ set res {}
+} -body {
+ for {set i 1} {$i < 5} {incr i} {
+ # 0 1 2 3 4
+ # 012345 678901234 567890123 456789012 34567890123456789
+ .mytop.t insert end "Line $i+++Line $i---Line $i///Line $i - This is Line [format %c [expr 64+$i]]\n"
+ }
+ .mytop.t tag configure hidden -elide true
+ .mytop.t tag add hidden 2.15 3.10
+ .mytop.t configure -wrap char
+ lappend res [.mytop.t count -displaylines 2.0 3.0]
+ lappend res [.mytop.t count -displaylines 2.0 3.40]
+} -cleanup {
+ destroy .mytop
+} -result {1 3}
# Newer tags are higher priority
.t tag configure elide1 -elide 0