Tk Source Code

View Ticket
Login
Ticket UUID: 587937
Title: Don't shuffle tag list sequence
Type: RFE Version: None
Submitter: wangnick Created on: 2002-07-29 08:23:09
Subsystem: 04. Canvas Basics Assigned To: fvogel
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2020-01-18 11:33:23
Resolution: Fixed Closed By: fvogel
    Closed on: 2020-01-18 11:33:23
Description:
Canvas should not shuffle the tag list sequence (on
which I'm relying to retrieve "dynamic option"
parameters) in dtag.

Current code:

for (i = itemPtr->numTags-1; i >= 0; i--) {
if (itemPtr->tagPtr[i] == tag) {
    itemPtr->tagPtr[i] = itemPtr->tagPtr[itemPtr->numTags-1];
    itemPtr->numTags--;
}
    }

Rather, it should use memmove to delete the tag.
User Comments: fvogel added on 2020-01-18 11:33:23:
Merged into core-8-6-branch and trunk.

fvogel added on 2019-12-24 14:26:13:

I have fixed tags sequence shuffling on removal.

See branch bug-587937fff.

In the process I have found an oddity: [.c addtags] only adds tags that are not already present, but [.c itemconfigure -tags] may add the same tag multiple times. I didn't change this. The tag deletion code did support removal of multiple tags of the same name before the shuffle fix, and it still does.


fvogel added on 2019-12-23 23:28:38:

Demo script showing the shuffling:

package require Tk
canvas .c
.c create text 100 100 -anchor nw -text Hello
for {set i 1} {$i < 5} {incr i} {
    .c addtag tag$i all
}
.c gettags 1    ; #  -->  tag1 tag2 tag3 tag4
.c dtag 1 tag2
.c gettags 1    ; #  -->  tag1 tag4 tag3 (shuffled)

Despite the manual does not promise the canvas item tag order is unaffected by deletions, I can understand the arguments pushed forward by the OP.

Moreover this looks easy to fix. Will do.


wangnick added on 2002-08-26 17:45:23:
Logged In: YES 
user_id=202812

Hey, this is the canvas, not TkTable ;) 

When I itemconfigure -tags to a certain list, I don't expect this 
list to be shuffled behind my back. Also, I can gain some 
performance by lsearch-ing the tag list with -exact to lookup 
a "marker" tag, and then retrieve data attached to the canvas 
item from the next list element.

hobbs added on 2002-08-08 12:08:28:
Logged In: YES 
user_id=72656

Isn't this irrelevant?  Aren't tags always returned in priority 
order?