From 0b63948d750367c7c5b44c522214d786346c2c99 Mon Sep 17 00:00:00 2001 From: fvogel Date: Wed, 3 Dec 2014 23:16:02 +0000 Subject: Checked dlineinfo caller of FindDLine, comments added --- generic/tkTextDisp.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c index c3ea9e0..b9790db 100644 --- a/generic/tkTextDisp.c +++ b/generic/tkTextDisp.c @@ -6972,6 +6972,15 @@ TkTextDLineInfo( */ dlPtr = FindDLine(textPtr, dInfoPtr->dLinePtr, indexPtr); + + /* + * Two cases shall be trapped here because the logic later really + * needs dlPtr to be the display line containing indexPtr: + * 1. if no display line contains the desired index (NULL dlPtr) + * 2. if indexPtr is before the first display line, in which case + * dlPtr currently points to the first display line + */ + if ((dlPtr == NULL) || (TkTextIndexCmp(&dlPtr->index, indexPtr) > 0)) { return -1; } -- cgit v0.12 From c7ee596aacc4f04a2e466283ffff7545bd946171 Mon Sep 17 00:00:00 2001 From: fvogel Date: Wed, 3 Dec 2014 23:18:42 +0000 Subject: Changed variable name for a better one --- generic/tkTextDisp.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c index b9790db..f17994b 100644 --- a/generic/tkTextDisp.c +++ b/generic/tkTextDisp.c @@ -6812,7 +6812,7 @@ TkTextIndexBbox( TextDInfo *dInfoPtr = textPtr->dInfoPtr; DLine *dlPtr; register TkTextDispChunk *chunkPtr; - int byteIndex; + int byteCount; /* * Make sure that all of the screen layout information is up to date. @@ -6844,20 +6844,20 @@ TkTextIndexBbox( * Find the chunk within the display line that contains the desired * index. The chunks making the display line are skipped up to but not * including the one crossing indexPtr. Skipping is done based on - * a byteIndex offset possibly spanning several logical lines in case + * a byteCount offset possibly spanning several logical lines in case * they are elided. */ - byteIndex = TkTextIndexCount(textPtr, &dlPtr->index, indexPtr, + byteCount = TkTextIndexCount(textPtr, &dlPtr->index, indexPtr, COUNT_INDICES); for (chunkPtr = dlPtr->chunkPtr; ; chunkPtr = chunkPtr->nextPtr) { if (chunkPtr == NULL) { return -1; } - if (byteIndex < chunkPtr->numBytes) { + if (byteCount < chunkPtr->numBytes) { break; } - byteIndex -= chunkPtr->numBytes; + byteCount -= chunkPtr->numBytes; } /* @@ -6867,13 +6867,13 @@ TkTextIndexBbox( * coordinate on the screen. Translate it to reflect horizontal scrolling. */ - (*chunkPtr->bboxProc)(textPtr, chunkPtr, byteIndex, + (*chunkPtr->bboxProc)(textPtr, chunkPtr, byteCount, dlPtr->y + dlPtr->spaceAbove, dlPtr->height - dlPtr->spaceAbove - dlPtr->spaceBelow, dlPtr->baseline - dlPtr->spaceAbove, xPtr, yPtr, widthPtr, heightPtr); *xPtr = *xPtr + dInfoPtr->x - dInfoPtr->curXPixelOffset; - if ((byteIndex == chunkPtr->numBytes-1) && (chunkPtr->nextPtr == NULL)) { + if ((byteCount == chunkPtr->numBytes-1) && (chunkPtr->nextPtr == NULL)) { /* * Last character in display line. Give it all the space up to the * line. -- cgit v0.12 From 09364e166b009ca51c07b86c91d868fe0a7cd9b5 Mon Sep 17 00:00:00 2001 From: fvogel Date: Wed, 3 Dec 2014 23:19:33 +0000 Subject: Fixed typos in comments --- tests/textDisp.test | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/textDisp.test b/tests/textDisp.test index a3f9ae9..3b5eca2 100644 --- a/tests/textDisp.test +++ b/tests/textDisp.test @@ -1458,7 +1458,7 @@ test textDisp-11.15 {TkTextSetYView, only a few lines visible} { update .top.t see 11.0 .top.t index @0,0 - # Thie index 9.0 should be just visible by a couple of pixels + # The index 9.0 should be just visible by a couple of pixels } {9.0} test textDisp-11.16 {TkTextSetYView, only a few lines visible} { .top.t yview 8.0 @@ -1471,7 +1471,7 @@ test textDisp-11.17 {TkTextSetYView, only a few lines visible} { update .top.t see 4.0 .top.t index @0,0 - # Thie index 2.0 should be just visible by a couple of pixels + # The index 2.0 should be just visible by a couple of pixels } {2.0} destroy .top -- cgit v0.12 From f2693008ed014c61875f98b5014116ccc9eb6764 Mon Sep 17 00:00:00 2001 From: fvogel Date: Wed, 3 Dec 2014 23:25:43 +0000 Subject: Fixed text see command for elided target indices. --- generic/tkTextDisp.c | 95 ++++++++++++++++++++++++++++------------------------ tests/textDisp.test | 16 ++++++++- 2 files changed, 66 insertions(+), 45 deletions(-) diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c index f17994b..3d442af 100644 --- a/generic/tkTextDisp.c +++ b/generic/tkTextDisp.c @@ -5056,19 +5056,20 @@ TkTextSetYView( */ dlPtr = NULL; - } else if ((dlPtr->index.linePtr == indexPtr->linePtr) - && (dlPtr->index.byteIndex <= indexPtr->byteIndex)) { - if (dInfoPtr->dLinePtr == dlPtr && dInfoPtr->topPixelOffset != 0) { - /* - * It is on the top line, but that line is hanging off the top - * of the screen. Change the top overlap to zero and update. - */ - - dInfoPtr->newTopPixelOffset = 0; - goto scheduleUpdate; - } - return; - } + } else { + if (TkTextIndexCmp(&dlPtr->index, indexPtr) <= 0) { + if (dInfoPtr->dLinePtr == dlPtr && dInfoPtr->topPixelOffset != 0) { + /* + * It is on the top line, but that line is hanging off the top + * of the screen. Change the top overlap to zero and update. + */ + + dInfoPtr->newTopPixelOffset = 0; + goto scheduleUpdate; + } + return; + } + } } /* @@ -5379,8 +5380,8 @@ TkTextSeeCmd( } /* - * Find the chunk that contains the desired index. dlPtr may be NULL if - * the widget is not mapped. [Bug #641778] + * Find the display line containing the desired index. dlPtr may be NULL + * if the widget is not mapped. [Bug #641778] */ dlPtr = FindDLine(textPtr, dInfoPtr->dLinePtr, &index); @@ -5388,7 +5389,16 @@ TkTextSeeCmd( return TCL_OK; } - byteCount = index.byteIndex - dlPtr->index.byteIndex; + /* + * Find the chunk within the display line that contains the desired + * index. The chunks making the display line are skipped up to but not + * including the one crossing index. Skipping is done based on a + * byteCount offset possibly spanning several logical lines in case + * they are elided. + */ + + byteCount = TkTextIndexCount(textPtr, &dlPtr->index, &index, + COUNT_INDICES); for (chunkPtr = dlPtr->chunkPtr; chunkPtr != NULL ; chunkPtr = chunkPtr->nextPtr) { if (byteCount < chunkPtr->numBytes) { @@ -5399,36 +5409,33 @@ TkTextSeeCmd( /* * Call a chunk-specific function to find the horizontal range of the - * character within the chunk. chunkPtr is NULL if trying to see in elided - * region. + * character within the chunk. */ - if (chunkPtr != NULL) { - (*chunkPtr->bboxProc)(textPtr, chunkPtr, byteCount, - dlPtr->y + dlPtr->spaceAbove, - dlPtr->height - dlPtr->spaceAbove - dlPtr->spaceBelow, - dlPtr->baseline - dlPtr->spaceAbove, &x, &y, &width, - &height); - delta = x - dInfoPtr->curXPixelOffset; - oneThird = lineWidth/3; - if (delta < 0) { - if (delta < -oneThird) { - dInfoPtr->newXPixelOffset = (x - lineWidth/2); - } else { - dInfoPtr->newXPixelOffset -= ((-delta) ); - } - } else { - delta -= (lineWidth - width); - if (delta > 0) { - if (delta > oneThird) { - dInfoPtr->newXPixelOffset = (x - lineWidth/2); - } else { - dInfoPtr->newXPixelOffset += (delta ); - } - } else { - return TCL_OK; - } - } + (*chunkPtr->bboxProc)(textPtr, chunkPtr, byteCount, + dlPtr->y + dlPtr->spaceAbove, + dlPtr->height - dlPtr->spaceAbove - dlPtr->spaceBelow, + dlPtr->baseline - dlPtr->spaceAbove, &x, &y, &width, + &height); + delta = x - dInfoPtr->curXPixelOffset; + oneThird = lineWidth/3; + if (delta < 0) { + if (delta < -oneThird) { + dInfoPtr->newXPixelOffset = (x - lineWidth/2); + } else { + dInfoPtr->newXPixelOffset -= ((-delta) ); + } + } else { + delta -= (lineWidth - width); + if (delta > 0) { + if (delta > oneThird) { + dInfoPtr->newXPixelOffset = (x - lineWidth/2); + } else { + dInfoPtr->newXPixelOffset += (delta ); + } + } else { + return TCL_OK; + } } dInfoPtr->flags |= DINFO_OUT_OF_DATE; if (!(dInfoPtr->flags & REDRAW_PENDING)) { diff --git a/tests/textDisp.test b/tests/textDisp.test index 3b5eca2..fff52d4 100644 --- a/tests/textDisp.test +++ b/tests/textDisp.test @@ -1473,7 +1473,21 @@ test textDisp-11.17 {TkTextSetYView, only a few lines visible} { .top.t index @0,0 # The index 2.0 should be just visible by a couple of pixels } {2.0} -destroy .top +test textDisp-11.18 {TkTextSetYView, see in elided lines} { + .top.t delete 1.0 end + for {set i 1} {$i < 20} {incr i} { + .top.t insert end [string repeat "Line $i" 10] + .top.t insert end "\n" + } + .top.t yview 4.0 + .top.t tag add hidden 4.10 "4.10 lineend" + .top.t tag add hidden 5.15 10.3 + .top.t tag configure hidden -elide true + update + .top.t see "8.0 lineend" + # The index "8.0 lineend" is on screen despite elided -> no scroll + .top.t index @0,0 +} {4.0} .t configure -wrap word .t delete 50.0 51.0 -- cgit v0.12