summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
Diffstat (limited to 'generic')
-rw-r--r--generic/tkTextBTree.c34
-rw-r--r--generic/tkTextDisp.c28
2 files changed, 27 insertions, 35 deletions
diff --git a/generic/tkTextBTree.c b/generic/tkTextBTree.c
index 005ce46..67ff79d 100644
--- a/generic/tkTextBTree.c
+++ b/generic/tkTextBTree.c
@@ -1991,17 +1991,37 @@ TkBTreeLinesTo(
index += nodePtr2->numLines;
}
}
- if (textPtr != NULL && textPtr->start != NULL) {
- index -= TkBTreeLinesTo(NULL, textPtr->start);
- if (index < 0) {
- /* One should panic here!
- Tcl_Panic("TkBTreeLinesTo: linePtr comes before -startline");
- */
+ if (textPtr != NULL) {
+ /*
+ * The index to return must be relative to textPtr, not to the entire
+ * tree. Take care to never return a negative index when linePtr
+ * denotes a line before -startline, or an index larger than the
+ * number of lines in textPtr when linePtr is a line past -endline.
+ */
+
+ int indexStart, indexEnd;
+
+ if (textPtr->start != NULL) {
+ indexStart = TkBTreeLinesTo(NULL, textPtr->start);
+ } else {
+ indexStart = 0;
+ }
+ if (textPtr->end != NULL) {
+ indexEnd = TkBTreeLinesTo(NULL, textPtr->end);
+ } else {
+ indexEnd = TkBTreeNumLines(textPtr->sharedTextPtr->tree, NULL);
+ }
+ if (index < indexStart) {
+ index = 0;
+ } else if (index > indexEnd) {
+ index = TkBTreeNumLines(textPtr->sharedTextPtr->tree, textPtr);
+ } else {
+ index -= indexStart;
}
}
return index;
}
-
+
/*
*----------------------------------------------------------------------
*
diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c
index f674b75..61fb76e 100644
--- a/generic/tkTextDisp.c
+++ b/generic/tkTextDisp.c
@@ -3219,34 +3219,6 @@ TextInvalidateLineMetrics(
int fromLine;
TextDInfo *dInfoPtr = textPtr->dInfoPtr;
- /*
- * All lines to invalidate must be inside the -startline/-endline range.
- */
-
- if (linePtr != NULL) {
- int start;
- TkTextLine *toLinePtr;
- if (textPtr->start != NULL) {
- fromLine = TkBTreeLinesTo(NULL, linePtr);
- start = TkBTreeLinesTo(NULL, textPtr->start);
- if (fromLine < start) {
- lineCount -= start - fromLine;
- linePtr = textPtr->start;
- }
- }
- if (textPtr->end != NULL) {
- int count = 0;
- toLinePtr = linePtr;
- while (count < lineCount && toLinePtr != NULL) {
- toLinePtr = TkBTreeNextLine(textPtr, toLinePtr);
- count++;
- }
- if (toLinePtr == NULL) {
- lineCount = count;
- }
- }
- }
-
if (linePtr != NULL) {
int counter = lineCount;