diff options
author | fvogel <fvogelnew1@free.fr> | 2012-02-18 21:55:28 (GMT) |
---|---|---|
committer | fvogel <fvogelnew1@free.fr> | 2012-02-18 21:55:28 (GMT) |
commit | 1487608db176d526e0c03938073340f5f2a068eb (patch) | |
tree | b3a7813f9f7a65cfa210096ad03d36a777bc56e0 | |
parent | 3ea0c8057eebd5bf0c51ec97477ef0715fb8d33b (diff) | |
download | tk-bug_1630262.zip tk-bug_1630262.tar.gz tk-bug_1630262.tar.bz2 |
Bug-3487407: Weird text indicesbug_1630262
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | generic/tkText.c | 4 | ||||
-rw-r--r-- | generic/tkTextDisp.c | 2 | ||||
-rw-r--r-- | generic/tkTextMark.c | 26 | ||||
-rw-r--r-- | tests/textMark.test | 7 |
5 files changed, 41 insertions, 7 deletions
@@ -1,4 +1,11 @@ -2012-01-?? Francois Vogel <fvogelnew1@free.fr> +2012-02-?? Francois Vogel <fvogelnew1@free.fr> + + * generic/tkText.c: [Bug-3487407]: Weird text indices. + * generic/tkTextDisp.c + * generic/tkTextMark.c + * tests/textMark.test + +2012-02-?? Francois Vogel <fvogelnew1@free.fr> * generic/tkText.c: [Bug-1630262] and [Bug-1615425]: segfault * generic/tkTextBTree.c when deleting lines or tagging outside of diff --git a/generic/tkText.c b/generic/tkText.c index 18cbcf4..6652f3d 100644 --- a/generic/tkText.c +++ b/generic/tkText.c @@ -2107,6 +2107,10 @@ ConfigureText( * Also, clamp the insert and current (unshared) marks to the new * -startline/-endline range limits of the widget. All other (shared) * marks are unchanged. + * The return value of TkTextMarkNameToIndex does not need to be + * checked: "insert" and "current" marks always exist, and the + * purpose of the code below precisely is to move them inside the + * -startline/-endline range. */ textPtr->sharedTextPtr->stateEpoch++; diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c index 61fb76e..d0cd4d2 100644 --- a/generic/tkTextDisp.c +++ b/generic/tkTextDisp.c @@ -1971,7 +1971,7 @@ UpdateDisplayInfo( if (spaceLeft <= dInfoPtr->newTopPixelOffset) { /* - * We can full up all the needed space just by showing more of the + * We can fill up all the needed space just by showing more of the * current top line. */ 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. diff --git a/tests/textMark.test b/tests/textMark.test index c1138ac..67b9ae5 100644 --- a/tests/textMark.test +++ b/tests/textMark.test @@ -170,6 +170,13 @@ test textMark-6.4 {TkTextMarkNameToIndex, with mark outside -startline/-endline .pt configure -startline {} -endline {} .t mark unset mymark } -result {1 {bad text index "mymark"} 1.0 1.0 1 {bad text index "mymark"} L 1 {bad text index "mymark"}} +test textMark-6.5 {insert and current marks in an empty peer - bug 3487407} -body { + .t mark set insert 1.0 + .t configure -start 5 -end 5 + set res [.t index insert] +} -cleanup { + .t configure -startline {} -endline {} +} -result {1.0} catch {eval {.t mark unset} [.t mark names]} test textMark-7.1 {MarkFindNext - invalid mark name} haveCourier12 { |