Tk Source Code

View Ticket
Login
Ticket UUID: cef1ef9d52bc34ec05d10bfee41bc8b86c16da2e
Title: Revised [text]: edit undo of insertions without separators leaves text behind or fails an assertion
Type: Bug Version: revised_text
Submitter: nab Created on: 2026-10-11 12:42:12
Subsystem: 18. [text] Assigned To: nobody
Priority: 5 Medium Severity: Important
Status: Closed Last Modified: 2026-10-11 12:58:56
Resolution: Fixed Closed By: nab
    Closed on: 2026-10-11 12:58:56
Description:

With -autoseparators 0, undoing four insertions should give back the empty text, as the legacy widget does. Revised_text leaves b, and then edit canundo returns 0:

text .t -undo 1 -autoseparators 0
.t insert end ab
.t insert 1.1 "x\nz"
.t insert 2.0 w
.t insert 1.0 "\n"
.t edit undo
.t get 1.0 end-1c

With a debug build, a similar sequence fails CheckByteIndex(indexPtr, indexPtr->priv.linePtr, byteIndex) in TkTextIndexSetByteIndex:

text .t -undo 1 -autoseparators 0
.t insert end abc
.t insert 1.1 "\nz"
.t insert 2.0 w
.t insert 1.0 "\n"
.t edit undo

and this one, with tags, fails indexPtr->priv.linePtr->nextPtr:

text .t -undo 1 -autoseparators 0
.t insert end lhld B
.t insert 1.1 "uu\na" C
.t insert 2.0 uodd
.t insert 1.0 "\n" B
.t edit undo

In the three cases the last insertion is a newline at 1.0, after an insertion that split a line. Found by fuzzing; I have not looked for the cause.

User Comments: nab added on 2026-10-11 12:58:56:

Fixed in [9af0137a76|9af0137a76], merged into revised_text with [3b01d124eb|3b01d124eb]. TkBTreeJoinUndoInsert joined a new insertion with the previous undo token when the new text ended where that token started, but the new text had shifted it, so the token no longer designated the text it recorded. Only appends are joined now. Tests text-27.48 to 27.50.