Tk Source Code

View Ticket
Login
2026-10-11
12:46 • Closed ticket [f39133da]: Revised text: undoing a tag priority change releases the tag twice plus 6 other changes artifact: 15bfe0d4 user: nab
12:46
Merge nab-tag-priority-undo: fix [f39133da29], undoing a tag priority change released the tag twice (test textTag-20.1). check-in: d42058c4 user: nab tags: revised_text, tip-466
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
Fix [f39133da29]: undoing a tag priority change released the tag twice. The priority undo token is replayed without pushing a new retained token, gets the undo or redo type like the mark tokens, and keeps its tag reference when it is reused. Test textTag-20.1. closed check-in: 649eae30 user: nab tags: nab-tag-priority-undo
12:41 • New ticket [f39133da] Revised text: undoing a tag priority change releases the tag twice. artifact: 1a503447 user: nab

Ticket UUID: f39133da29604cd301d357c8f393dd90cc284019
Title: Revised [text]: undoing a tag priority change releases the tag twice
Type: Bug Version: revised_text
Submitter: nab Created on: 2026-10-11 12:41:57
Subsystem: 18. [text] Assigned To: nobody
Priority: 5 Medium Severity: Important
Status: Closed Last Modified: 2026-10-11 12:46:47
Resolution: Fixed Closed By: nab
    Closed on: 2026-10-11 12:46:47
Description:

In the revised text widget, undoing tag raise or tag lower makes the tag lose one reference too many. With a debug build (--enable-symbols), this script fails !tagPtr->recentChangePriorityToken in TkTextReleaseTag at the second undo:

text .t -undo 1
.t tag configure B
.t tag configure P
.t tag raise B
.t edit undo
.t edit redo
.t edit undo

and this one fails tagPtr->refCount > 1 || !tagPtr->rootPtr in TkTextReleaseTag when the widget is destroyed:

text .t -undo 1
.t tag configure B
.t tag configure P
.t tag raise B
.t edit undo
.t insert 1.0 x B
destroy .t

Without assertions, the reference count of the tag drops to zero while the text still uses it.

UndoChangeTagPriorityPerform calls ChangeTagPriority with undo set, so replaying the token creates a second, retained token for the same change, and it always gives the reused token the redo type. UndoChangeTagPriorityDestroy ignores its reused argument and releases the tag even when the token lives on as the redo item. The undo tokens of marks (UndoToggleGravityPerform, UndoMoveMarkPerform) do it the other way: no new undo item while replaying, the type depends on isRedo, and no release when the token is reused.

Fix in branch nab-tag-priority-undo, with test textTag-20.1 (raise, undo, redo, undo, then destroy; without the fix it fails the assertion at the second undo). On a debug build on macOS, text*.test pass, and a fuzzer that mixes tag priority changes with undo and redo no longer fails in TkTextReleaseTag.

User Comments: nab added on 2026-10-11 12:46:47:

Merged into revised_text with [d42058c412|d42058c412].