diff options
author | fvogel <fvogelnew1@free.fr> | 2014-11-21 22:10:15 (GMT) |
---|---|---|
committer | fvogel <fvogelnew1@free.fr> | 2014-11-21 22:10:15 (GMT) |
commit | fec6c46dcba3131cd66f024a3eae77a9e9e446fa (patch) | |
tree | fc9942a507f7e2135def8320586cf02a926bfa5a /generic/tkText.c | |
parent | 9d5ff2c244a14567d97787d96edb42a207783f41 (diff) | |
download | tk-fec6c46dcba3131cd66f024a3eae77a9e9e446fa.zip tk-fec6c46dcba3131cd66f024a3eae77a9e9e446fa.tar.gz tk-fec6c46dcba3131cd66f024a3eae77a9e9e446fa.tar.bz2 |
Fixed bug [c24b97d905] - text count -displaylines is wrong with elided newlines
Diffstat (limited to 'generic/tkText.c')
-rw-r--r-- | generic/tkText.c | 53 |
1 files changed, 31 insertions, 22 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); |