diff options
author | fvogel <fvogelnew1@free.fr> | 2016-02-08 21:13:57 (GMT) |
---|---|---|
committer | fvogel <fvogelnew1@free.fr> | 2016-02-08 21:13:57 (GMT) |
commit | d00d37bf4da1bd2c0ac1548af910aea41a4e1289 (patch) | |
tree | 89bcb05e9c6bfa950e448424a1a80d2f1119a0cd /generic | |
parent | afd2fa759f72c2936c5fcec0449acbaaaa93f989 (diff) | |
download | tk-d00d37bf4da1bd2c0ac1548af910aea41a4e1289.zip tk-d00d37bf4da1bd2c0ac1548af910aea41a4e1289.tar.gz tk-d00d37bf4da1bd2c0ac1548af910aea41a4e1289.tar.bz2 |
Made FindDLine fully match its header description.
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tkTextDisp.c | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c index d45ac73..4d41134 100644 --- a/generic/tkTextDisp.c +++ b/generic/tkTextDisp.c @@ -6590,6 +6590,7 @@ FindDLine( CONST TkTextIndex *indexPtr)/* Index of desired character. */ { DLine *dlPtrPrev; + TkTextIndex indexPtr2; if (dlPtr == NULL) { return NULL; @@ -6614,7 +6615,6 @@ FindDLine( dlPtrPrev = dlPtr; dlPtr = dlPtr->nextPtr; if (dlPtr == NULL) { - TkTextIndex indexPtr2; /* * We're past the last display line, either because the desired * index lies past the visible text, or because the desired index @@ -6632,14 +6632,41 @@ FindDLine( } else { /* * The desired index is past the visible text. There is no - * display line displaying something at the desired index + * display line displaying something at the desired index. * --> return NULL. */ } break; } if (TkTextIndexCmp(&dlPtr->index,indexPtr) > 0) { - dlPtr = dlPtrPrev; + /* + * If we're here then we would normally expect that: + * dlPtrPrev->index <= indexPtr < dlPtr->index + * i.e. we have found the searched display line being dlPtr. + * However it is possible that some DLines were unlinked + * previously, leading to a situation where going through + * the list of display lines skips display lines that did + * exist just a moment ago. + */ + indexPtr2 = dlPtrPrev->index; + TkTextIndexForwBytes(textPtr, &indexPtr2, dlPtrPrev->byteCount, + &indexPtr2); + if (TkTextIndexCmp(&indexPtr2,indexPtr) > 0) { + /* + * Confirmed: + * dlPtrPrev->index <= indexPtr < dlPtr->index + * --> return dlPtrPrev. + */ + dlPtr = dlPtrPrev; + } else { + /* + * The last (rightmost) index shown by dlPtrPrev is still + * before the desired index. This may be because there was + * previously a display line between dlPtrPrev and dlPtr + * and this display line has been unlinked. + * --> return dlPtr. + */ + } break; } } |