Tktext: insert with multiple (chars, taglist) not working properly

The ruby tktext documentation lists

insert(index, chars, ?tagList, chars, tagList, …?) :
[…] If tagList is specified then it consists of a list of tag names;
the new characters will receive all of the tags in this list and no
others, regardless of the tags present around the insertion point. If
multiple chars-tagList argument pairs are present, they produce the
same effect as if a separate insert widget command had been issued for
each pair, in order. The last tagList argument may be omitted.

I tried the following code (where a is an array of alternating text,
TkTextTag and pos = ‘end’):

   insert(pos, *a)
   insert(pos, "\n")
   a.each_slice(2) {|i, j| insert(pos, i, j)}

which produces the following screenshot:

(The first line is not what I wanted, the second and third lines are
what should have been printed). It looks like it’s taking the first
text, and then merging all the tags via something analogous to
hash#update. Is this a bug or am I doing something wrong?

Here’s the value of a.inspect in case it reveals anything:

[“hello world”, #<TkTextTag:0x00000001c5b9c0
@path=“.w00003.w00004”>, @tpath=“.w00003.w00004”, @id=“tag00000”,
@path=“tag00000”>, “Bold red text on blue:\n”,
@path=“.w00003.w00004”>, @tpath=“.w00003.w00004”, @id=“tag00001”,
@path=“tag00001”>, “Green text on blue”, #<TkTextTag:0x000000023540b0
@path=“.w00003.w00004”>, @tpath=“.w00003.w00004”, @id=“tag00002”,
@path=“tag00002”>, “none\n”, #<TkTextTag:0x0000000235f7f8
@path=“.w00003.w00004”>, @tpath=“.w00003.w00004”, @id=“tag00003”,


Complete minimal program reproducing the problem:

require ‘tk’

root = { title “TkMarkupText” }
display =
text =
display.pack(“fill”=>“both”, “expand”=>true)
text.pack(“fill”=>“both”, “expand”=>true)

tags = [
[“hello world”, {}],
[“Bold red text on blue:\n”, {:font=>[:bold], :foreground=>“red”,
[“Green text on blue”, {:background=>“blue”, :foreground=>“green”}],
[“none\n”, {}]
].map {|t, tag| [t,, tag)]}.flatten

text.insert(“end”, *tags)



Figured it out - it should have been insert(pos, text, [tag], text,
[tag]) rather than insert(pos, text, tag, text, tag). It was staring
me in the face! I finally realised the docs said “tagList” rather than