Tk Source Code

Check-in [f39a8001]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Bug-3487407: Weird text indices
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | bug-1630262
Files: files | file ages | folders
SHA1: f39a80017a4c56e5f854a0096ebb26359aef3ef4
User & Date: fvogel 2012-02-18 21:55:28
Context
2012-02-28
20:14
[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. check-in: 6dfcc8fc user: fvogel tags: core-8-5-branch
2012-02-18
21:55
Bug-3487407: Weird text indices Closed-Leaf check-in: f39a8001 user: fvogel tags: bug-1630262
2012-02-03
21:45
Updated changelog to take bug-1615425 into account check-in: c2631a86 user: fvogel tags: bug-1630262
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ChangeLog.

1







2
3
4
5
6
7
8
2012-01-??  Francois Vogel  <[email protected]>








	* generic/tkText.c:      [Bug-1630262] and [Bug-1615425]: segfault
	* generic/tkTextBTree.c  when deleting lines or tagging outside of
	* generic/tkTextDisp.c   the -startline/-endline range with peer
	* tests/text.test        text widgets.

2012-01-29  Jan Nijtmans  <[email protected]>
|
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2012-02-??  Francois Vogel  <[email protected]>

	* generic/tkText.c:      [Bug-3487407]: Weird text indices.
	* generic/tkTextDisp.c
	* generic/tkTextMark.c
	* tests/textMark.test

2012-02-??  Francois Vogel  <[email protected]>

	* generic/tkText.c:      [Bug-1630262] and [Bug-1615425]: segfault
	* generic/tkTextBTree.c  when deleting lines or tagging outside of
	* generic/tkTextDisp.c   the -startline/-endline range with peer
	* tests/text.test        text widgets.

2012-01-29  Jan Nijtmans  <[email protected]>

Changes to generic/tkText.c.

2103
2104
2105
2106
2107
2108
2109




2110
2111
2112
2113
2114
2115
2116
	}

	/* Indices are potentially obsolete after changing -startline and/or
	 * -endline, therefore increase the epoch.
	 * Also, clamp the insert and current (unshared) marks to the new
	 * -startline/-endline range limits of the widget. All other (shared)
	 * marks are unchanged.




	 */

	textPtr->sharedTextPtr->stateEpoch++;
	TkTextMarkNameToIndex(textPtr, "insert", &index3);
	if (TkTextIndexCmp(&index3, &index1) < 0) {
	    textPtr->insertMarkPtr = TkTextSetMark(textPtr, "insert", &index1);
	}







>
>
>
>







2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
	}

	/* Indices are potentially obsolete after changing -startline and/or
	 * -endline, therefore increase the epoch.
	 * 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++;
	TkTextMarkNameToIndex(textPtr, "insert", &index3);
	if (TkTextIndexCmp(&index3, &index1) < 0) {
	    textPtr->insertMarkPtr = TkTextSetMark(textPtr, "insert", &index1);
	}

Changes to generic/tkTextDisp.c.

1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
	 * displayed, or the lines above it.
	 */

	int spaceLeft = maxY - y;

	if (spaceLeft <= dInfoPtr->newTopPixelOffset) {
	    /*
	     * We can full up all the needed space just by showing more of the
	     * current top line.
	     */

	    dInfoPtr->newTopPixelOffset -= spaceLeft;
	    y += spaceLeft;
	    spaceLeft = 0;
	} else {







|







1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
	 * displayed, or the lines above it.
	 */

	int spaceLeft = maxY - y;

	if (spaceLeft <= dInfoPtr->newTopPixelOffset) {
	    /*
	     * We can fill up all the needed space just by showing more of the
	     * current top line.
	     */

	    dInfoPtr->newTopPixelOffset -= spaceLeft;
	    y += spaceLeft;
	    spaceLeft = 0;
	} else {

Changes to generic/tkTextMark.c.

281
282
283
284
285
286
287

288
289
290
291
292
293
294
295
296
297
298







299


300
301
302
303
304
305
306
	 * If this is the insertion point that's being moved, be sure to force
	 * a display update at the old position. Also, don't let the insertion
	 * cursor be after the final newline of the file.
	 */

	if (markPtr == textPtr->insertMarkPtr) {
	    TkTextIndex index, index2;


	    TkTextMarkSegToIndex(textPtr, textPtr->insertMarkPtr, &index);
	    TkTextIndexForwChars(NULL,&index, 1, &index2, COUNT_INDICES);

	    /*
	     * While we wish to redisplay, no heights have changed, so no need
	     * to call TkTextInvalidateLineMetrics.
	     */

	    TkTextChanged(NULL, textPtr, &index, &index2);
	    if (TkBTreeLinesTo(textPtr, indexPtr->linePtr) ==







		    TkBTreeNumLines(textPtr->sharedTextPtr->tree, textPtr))  {


		TkTextIndexBackChars(NULL,indexPtr, 1, &insertIndex,
			COUNT_INDICES);
		indexPtr = &insertIndex;
	    }
	}
	TkBTreeUnlinkSegment(markPtr, markPtr->body.mark.linePtr);
    } else {







>










|
>
>
>
>
>
>
>
|
>
>







281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
	 * If this is the insertion point that's being moved, be sure to force
	 * a display update at the old position. Also, don't let the insertion
	 * cursor be after the final newline of the file.
	 */

	if (markPtr == textPtr->insertMarkPtr) {
	    TkTextIndex index, index2;
            int nblines;

	    TkTextMarkSegToIndex(textPtr, textPtr->insertMarkPtr, &index);
	    TkTextIndexForwChars(NULL,&index, 1, &index2, COUNT_INDICES);

	    /*
	     * While we wish to redisplay, no heights have changed, so no need
	     * to call TkTextInvalidateLineMetrics.
	     */

	    TkTextChanged(NULL, textPtr, &index, &index2);

            /*
             * 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;
	    }
	}
	TkBTreeUnlinkSegment(markPtr, markPtr->body.mark.linePtr);
    } else {
381
382
383
384
385
386
387

388
389
390





391
392
393
394
395
396
397
 * TkTextMarkNameToIndex --
 *
 *	Given the name of a mark, return an index corresponding to the mark
 *	name.
 *
 * 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.





 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */








>
|
|
|
>
>
>
>
>







391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
 * TkTextMarkNameToIndex --
 *
 *	Given the name of a mark, return an index corresponding to the mark
 *	name.
 *
 * Results:
 *	The return value is TCL_OK if "name" exists as a mark in the text
 *	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.
 *
 *--------------------------------------------------------------
 */

Changes to tests/textMark.test.

166
167
168
169
170
171
172







173
174
175
176
177
178
179
  lappend res [.t get mymark]
  lappend res [catch {.pt get mymark} msg] $msg
} -cleanup {
  .t configure -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"}}








catch {eval {.t mark unset} [.t mark names]}
test textMark-7.1 {MarkFindNext - invalid mark name} haveCourier12 {
    catch {.t mark next bogus} x
    set x
} {bad text index "bogus"}
test textMark-7.2 {MarkFindNext - marks at same location} haveCourier12 {







>
>
>
>
>
>
>







166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
  lappend res [.t get mymark]
  lappend res [catch {.pt get mymark} msg] $msg
} -cleanup {
  .t configure -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 {
    catch {.t mark next bogus} x
    set x
} {bad text index "bogus"}
test textMark-7.2 {MarkFindNext - marks at same location} haveCourier12 {