summaryrefslogtreecommitdiffstats
path: root/generic/tkTextMark.c
diff options
context:
space:
mode:
authorfvogel <fvogelnew1@free.fr>2012-02-28 20:44:34 (GMT)
committerfvogel <fvogelnew1@free.fr>2012-02-28 20:44:34 (GMT)
commit5f980e90395c85af59bb9286b197a620d8ba911f (patch)
treed62de6938569517afd6274d9096c99eadec78078 /generic/tkTextMark.c
parent9893c7fae421e1414f8e19acd5059350093c49c3 (diff)
parent220b6aecbb178564d3ee630cf19c6aa8ae93a67d (diff)
downloadtk-5f980e90395c85af59bb9286b197a620d8ba911f.zip
tk-5f980e90395c85af59bb9286b197a620d8ba911f.tar.gz
tk-5f980e90395c85af59bb9286b197a620d8ba911f.tar.bz2
[Bug-1630262], [Bug-1615425]: segfault when deleting lines or tagging outside of the -startline/-endline range with peer text widgets. [Bug-3487407]: Weird text indices.
Diffstat (limited to 'generic/tkTextMark.c')
-rw-r--r--generic/tkTextMark.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/generic/tkTextMark.c b/generic/tkTextMark.c
index 9729449..76ab1a9 100644
--- a/generic/tkTextMark.c
+++ b/generic/tkTextMark.c
@@ -286,6 +286,7 @@ TkTextSetMark(
if (markPtr == textPtr->insertMarkPtr) {
TkTextIndex index, index2;
+ int nblines;
TkTextMarkSegToIndex(textPtr, textPtr->insertMarkPtr, &index);
TkTextIndexForwChars(NULL, &index, 1, &index2, COUNT_INDICES);
@@ -296,9 +297,18 @@ TkTextSetMark(
*/
TkTextChanged(NULL, textPtr, &index, &index2);
- if (TkBTreeLinesTo(textPtr, indexPtr->linePtr) ==
- TkBTreeNumLines(textPtr->sharedTextPtr->tree, textPtr)) {
- TkTextIndexBackChars(NULL, indexPtr, 1, &insertIndex,
+
+ /*
+ * 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;
}
@@ -386,9 +396,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.