summaryrefslogtreecommitdiffstats
path: root/generic/tkText.c
diff options
context:
space:
mode:
authorfvogel <fvogelnew1@free.fr>2012-01-31 22:24:11 (GMT)
committerfvogel <fvogelnew1@free.fr>2012-01-31 22:24:11 (GMT)
commit7664c99658c07b63bcdfc3827dd74d8da19ef1fd (patch)
tree1f9ca7098989620146558e0736d079e2bad9d81f /generic/tkText.c
parentb4f5df095c7b84b7aa277daf88a07e38f6e03abc (diff)
downloadtk-7664c99658c07b63bcdfc3827dd74d8da19ef1fd.zip
tk-7664c99658c07b63bcdfc3827dd74d8da19ef1fd.tar.gz
tk-7664c99658c07b63bcdfc3827dd74d8da19ef1fd.tar.bz2
[Bug-1630262]: segfault when deleting lines with peer text widgets
Diffstat (limited to 'generic/tkText.c')
-rw-r--r--generic/tkText.c43
1 files changed, 41 insertions, 2 deletions
diff --git a/generic/tkText.c b/generic/tkText.c
index d050170..18cbcf4 100644
--- a/generic/tkText.c
+++ b/generic/tkText.c
@@ -3097,6 +3097,11 @@ DeleteIndexRange(
resetView = 1;
line = line1;
byteIndex = tPtr->topIndex.byteIndex;
+ } else {
+ /*
+ * Deletion range starts after the top line. This peers's view
+ * will not need to be reset. Nothing to do.
+ */
}
} else if (index2.linePtr == tPtr->topIndex.linePtr) {
/*
@@ -3113,6 +3118,11 @@ DeleteIndexRange(
} else {
byteIndex -= (index2.byteIndex - index1.byteIndex);
}
+ } else {
+ /*
+ * Deletion range ends before the top line. This peers's view
+ * will not need to be reset. Nothing to do.
+ */
}
if (resetView) {
lineAndByteIndex[resetViewCount] = line;
@@ -3157,14 +3167,43 @@ DeleteIndexRange(
TkTextIndex indexTmp;
if (tPtr == textPtr) {
- if (viewUpdate) {
+ if (viewUpdate) {
+ /*
+ * line cannot be before -startline of textPtr because
+ * this line corresponds to an index which is necessarily
+ * between "1.0" and "end" relative to textPtr.
+ * Therefore no need to clamp line to the -start/-end
+ * range.
+ */
+
TkTextMakeByteIndex(sharedTextPtr->tree, textPtr, line,
byteIndex, &indexTmp);
TkTextSetYView(tPtr, &indexTmp, 0);
}
} else {
- TkTextMakeByteIndex(sharedTextPtr->tree, NULL, line,
+ TkTextMakeByteIndex(sharedTextPtr->tree, tPtr, line,
byteIndex, &indexTmp);
+ /*
+ * line may be before -startline of tPtr and must be
+ * clamped to -startline before providing it to
+ * TkTextSetYView otherwise lines before -startline
+ * 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
+ */
+
+ if (tPtr->start != NULL) {
+ int start;
+ TkTextIndex indexStart;
+
+ start = TkBTreeLinesTo(NULL, tPtr->start);
+ TkTextMakeByteIndex(sharedTextPtr->tree, NULL, start,
+ 0, &indexStart);
+ if (TkTextIndexCmp(&indexTmp, &indexStart) < 0) {
+ indexTmp = indexStart;
+ }
+ }
TkTextSetYView(tPtr, &indexTmp, 0);
}
}