summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfvogel <fvogelnew1@free.fr>2021-04-18 11:54:03 (GMT)
committerfvogel <fvogelnew1@free.fr>2021-04-18 11:54:03 (GMT)
commitf910d73ddae2b049ae3c82bd3eb6c840ed2ef32c (patch)
treed9101aabc48d0c5ac72e6ff708a240a770de2366
parent4f342cf8461171eafee55086646adde29dd8631c (diff)
parentad62abdbadab35439f45dcb00a2cce9f18526da6 (diff)
downloadtk-f910d73ddae2b049ae3c82bd3eb6c840ed2ef32c.zip
tk-f910d73ddae2b049ae3c82bd3eb6c840ed2ef32c.tar.gz
tk-f910d73ddae2b049ae3c82bd3eb6c840ed2ef32c.tar.bz2
Fix [ea876b3e8a]: Text peer widget ignores set -startline when scrolling with the scrollbar.
-rw-r--r--generic/tkText.c16
-rw-r--r--generic/tkTextBTree.c20
-rw-r--r--tests/text.test4
-rw-r--r--tests/textDisp.test15
4 files changed, 41 insertions, 14 deletions
diff --git a/generic/tkText.c b/generic/tkText.c
index c41fc67..90ec575 100644
--- a/generic/tkText.c
+++ b/generic/tkText.c
@@ -3297,7 +3297,7 @@ DeleteIndexRange(
TkTextSetYView(tPtr, &indexTmp, 0);
}
} else {
- TkTextMakeByteIndex(sharedTextPtr->tree, tPtr, line,
+ TkTextMakeByteIndex(sharedTextPtr->tree, NULL, line,
byteIndex, &indexTmp);
/*
* line may be before -startline of tPtr and must be
@@ -3306,20 +3306,12 @@ DeleteIndexRange(
* would be displayed.
* There is no need to worry about -endline however,
* because the view will only be reset if the deletion
- * involves the TOP line of the screen
+ * involves the TOP line of the screen. That said,
+ * the following call adjusts to both.
*/
- if (tPtr->start != NULL) {
- int start;
- TkTextIndex indexStart;
+ TkTextIndexAdjustToStartEnd(tPtr, &indexTmp, 0);
- start = TkBTreeLinesTo(NULL, tPtr->start);
- TkTextMakeByteIndex(sharedTextPtr->tree, NULL, start,
- 0, &indexStart);
- if (TkTextIndexCmp(&indexTmp, &indexStart) < 0) {
- indexTmp = indexStart;
- }
- }
TkTextSetYView(tPtr, &indexTmp, 0);
}
}
diff --git a/generic/tkTextBTree.c b/generic/tkTextBTree.c
index 7832992..1b65cbc 100644
--- a/generic/tkTextBTree.c
+++ b/generic/tkTextBTree.c
@@ -1727,6 +1727,26 @@ TkBTreeFindPixelLine(
}
pixels -= linePtr->pixels[2 * pixelReference];
}
+
+ /*
+ * Check for any start/end offset for this text widget.
+ */
+
+ if (textPtr->start != NULL) {
+ int lineBoundary = TkBTreeLinesTo(NULL, textPtr->start);
+
+ if (TkBTreeLinesTo(NULL, linePtr) < lineBoundary) {
+ linePtr = TkBTreeFindLine(tree, NULL, lineBoundary);
+ }
+ }
+ if (textPtr->end != NULL) {
+ int lineBoundary = TkBTreeLinesTo(NULL, textPtr->end);
+
+ if (TkBTreeLinesTo(NULL, linePtr) > lineBoundary) {
+ linePtr = TkBTreeFindLine(tree, NULL, lineBoundary);
+ }
+ }
+
if (pixelOffset != NULL && linePtr != NULL) {
*pixelOffset = pixels;
}
diff --git a/tests/text.test b/tests/text.test
index 6bd0ae4..9ee0eff 100644
--- a/tests/text.test
+++ b/tests/text.test
@@ -7419,10 +7419,10 @@ test text-32.3 {peer widget -start, -end and deletion (bug 1630262)} -setup {
.pt delete 2.0 3.0
# moreover -startline shall be correct
# (was wrong before fixing bug 1630262)
- lappend res [.t cget -start] [.pt cget -start]
+ lappend res [.t cget -start] [.pt cget -start] [.t get @0,0 "@0,0 lineend"]
} -cleanup {
destroy .pt
-} -result {4 3}
+} -result {4 3 {Line 5}}
test text-32.4 {peer widget -start, -end and deletion (bug 1630262)} -setup {
destroy .t .pt
diff --git a/tests/textDisp.test b/tests/textDisp.test
index ac80069..b35a107 100644
--- a/tests/textDisp.test
+++ b/tests/textDisp.test
@@ -1660,6 +1660,21 @@ test textDisp-11.21 {TkTextSetYView, window height smaller than the line height}
.top.t see 1.0
.top.t index @0,[expr {$lineheight - 2}]
} {1.0}
+test textDisp-11.22 {TkTextSetYView, peer has -startline} {
+ .top.t delete 1.0 end
+ for {set i 1} {$i <= 50} {incr i} {
+ .top.t insert end "Line $i\n"
+ }
+ pack [.top.t peer create .top.p] -side left
+ pack [scrollbar .top.sb -command {.top.p yview}] -side left -fill y
+ .top.p configure -startline 5 -endline 35 -yscrollcommand {.top.sb set}
+ updateText
+ .top.p yview moveto 0
+ updateText
+ set res [.top.p get @0,0 "@0,0 lineend"]
+ destroy .top.p
+ set res
+} {Line 5}
.t configure -wrap word
.t delete 50.0 51.0