diff options
author | fvogelnew1@free.fr <fvogel> | 2012-02-18 21:55:28 (GMT) |
---|---|---|
committer | fvogelnew1@free.fr <fvogel> | 2012-02-18 21:55:28 (GMT) |
commit | 99d2897e216836eebc64f8de0b94c7e525419a61 (patch) | |
tree | b3a7813f9f7a65cfa210096ad03d36a777bc56e0 /generic/tkTextMark.c | |
parent | 8e4bf05bd090c5174f559b5ab00bf598bc92a902 (diff) | |
download | tk-99d2897e216836eebc64f8de0b94c7e525419a61.zip tk-99d2897e216836eebc64f8de0b94c7e525419a61.tar.gz tk-99d2897e216836eebc64f8de0b94c7e525419a61.tar.bz2 |
Bug-3487407: Weird text indices
Diffstat (limited to 'generic/tkTextMark.c')
-rw-r--r-- | generic/tkTextMark.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/generic/tkTextMark.c b/generic/tkTextMark.c index a9d709c..71a7949 100644 --- a/generic/tkTextMark.c +++ b/generic/tkTextMark.c @@ -285,6 +285,7 @@ TkTextSetMark( if (markPtr == textPtr->insertMarkPtr) { TkTextIndex index, index2; + int nblines; TkTextMarkSegToIndex(textPtr, textPtr->insertMarkPtr, &index); TkTextIndexForwChars(NULL,&index, 1, &index2, COUNT_INDICES); @@ -295,8 +296,17 @@ TkTextSetMark( */ TkTextChanged(NULL, textPtr, &index, &index2); - if (TkBTreeLinesTo(textPtr, indexPtr->linePtr) == - TkBTreeNumLines(textPtr->sharedTextPtr->tree, textPtr)) { + + /* + * The number of lines in the widget is zero if and only if it is + * a partial peer with -startline == -endline, i.e. an empty + * peer. In this case the mark shall be set exactly at the given + * index, and not one character backwards (bug 3487407). + */ + + nblines = TkBTreeNumLines(textPtr->sharedTextPtr->tree, textPtr); + if ((TkBTreeLinesTo(textPtr, indexPtr->linePtr) == nblines) + && (nblines > 0)) { TkTextIndexBackChars(NULL,indexPtr, 1, &insertIndex, COUNT_INDICES); indexPtr = &insertIndex; @@ -385,9 +395,15 @@ TkTextMarkSegToIndex( * * Results: * The return value is TCL_OK if "name" exists as a mark in the text - * widget. In this case *indexPtr is filled in with the next segment - * whose after the mark whose size is non-zero. TCL_ERROR is returned if - * the mark doesn't exist in the text widget. + * widget and is located within its -starline/-endline range. In this + * case *indexPtr is filled in with the next segment who is after the + * mark whose size is non-zero. TCL_ERROR is returned if the mark + * doesn't exist in the text widget, or if it is out of its -starline/ + * -endline range. In this latter case *indexPtr still contains valid + * information, in particular TkTextMarkNameToIndex called with the + * "insert" or "current" mark name may return TCL_ERROR, but *indexPtr + * contains the correct index of this mark before -startline or after + * -endline. * * Side effects: * None. |