From: Martin DeMello Date: 2012-11-24T19:27:29+09:00 Subject: Re: tktext: insert with multiple (chars, taglist) not working properly Complete minimal program reproducing the problem: require 'tk' root = TkRoot.new() { title "TkMarkupText" } display = TkFrame.new(root).pack text = TkText.new(display).pack display.pack("fill"=>"both", "expand"=>true) text.pack("fill"=>"both", "expand"=>true) text.focus tags = [ ["hello world", {}], ["Bold red text on blue:\n", {:font=>[:bold], :foreground=>"red", :background=>"blue"}], ["Green text on blue", {:background=>"blue", :foreground=>"green"}], ["none\n", {}] ].map {|t, tag| [t, TkTextTag.new(text, tag)]}.flatten text.insert("end", *tags) Tk.mainloop martin On Sat, Nov 24, 2012 at 1:13 AM, Martin DeMello wrote: > 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: > > http://imgur.com/Ktwh1 > > (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", # @t=# @path=".w00003.w00004">, > @parent=# @path=".w00003.w00004">, @tpath=".w00003.w00004", @id="tag00000", > @path="tag00000">, "Bold red text on blue:\n", > # @t=# @path=".w00003.w00004">, > @parent=# @path=".w00003.w00004">, @tpath=".w00003.w00004", @id="tag00001", > @path="tag00001">, "Green text on blue", # @t=# @path=".w00003.w00004">, > @parent=# @path=".w00003.w00004">, @tpath=".w00003.w00004", @id="tag00002", > @path="tag00002">, "none\n", # @t=# @path=".w00003.w00004">, > @parent=# @path=".w00003.w00004">, @tpath=".w00003.w00004", @id="tag00003", > @path="tag00003">] > > martin