Tk Source Code

View Ticket
Login
2026-10-11
12:58 • Closed ticket [cef1ef9d]: Revised text: edit undo of insertions without separators leaves text behind or fails an assertion plus 6 other changes artifact: e832e1e7 user: nab
12:58
Merge nab-undo-insert-join: fix [cef1ef9d52], undo of an insertion followed by one before it (tests text-27.48 to 27.50). check-in: 3b01d124 user: nab tags: revised_text, tip-466
12:58
Fix [cef1ef9d52]: an insertion was joined in the undo stack with the previous one when it ended where that one started, although it had shifted it, so the undo removed wrong ranges. Only appends are joined now. Tests text-27.48 to 27.50. closed check-in: 9af0137a user: nab tags: nab-undo-insert-join
12:42 • Ticket [05411ee5] Revised text: inserting text with an -elide 0 tag into an elided range fails an assertion status still Open with 3 other changes artifact: b1fe54b2 user: nab
12:42 • New ticket [cef1ef9d] Revised text: edit undo of insertions without separators leaves text behind or fails an assertion. artifact: d303e478 user: nab

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.