From: "Albert L. Wagner" Date: 2001-10-17T22:01:01+09:00 Subject: [ruby-talk:22672] Re: Ruby/Tk How to set a text mark Thank you, Hidetoshi. That's just what I needed. I'll let you know how it works out. nagai@ai.kyutech.ac.jp wrote: > > Hi, Hidetoshi > > From: Albert Wagner > Subject: [ruby-talk:22660] Ruby/Tk How to set a text mark > Date: Wed, 17 Oct 2001 10:58:59 +0900 > Message-ID: <20011017015718.OQWU18411.io@there> > alwagner> Can you help me to set a text mark? > > A text index must be String. > If you give a index 'line.char' as Float, > sometimes Ruby/Tk misunderstands it. > ( for example, 2.10 ==> '2.1' ) > > If you want to use TkTextMark with modifires, > you will have to use TkTextMark#id method. > The method returns the mark name on Tk. > By using the name, you must generate index description. > > For example, > ------------------------------------------------ > t = TkText.new.pack > t.insert('1.0', "0123456789\nABCDEFGHIJKLMN\nabcdefghijklmn\n") > m1 = TkTextMark.new(t, '1.end') > m2 = TkTextMark.new(t, '2.10') > m3 = TkTextMark.new(t, '@20,40') # coordinate on the text widget > p t.mark_names #=> return array of TkTextMark objects > p t.index(m1) #=> "1.10" > p t.index(m3) #=> for example, "3.2" > p t.index(m2.id + ' lineend') #=> "2.14" > p t.index(m2.id + ' + 1 lines - 5 chars')#=> "3.5" > p t.compare(m1, '<', m2) #=> true > p t.compare(m1, '>', m2) #=> false > p t.get(m1,m2) #=> "\nABCDEFGHIJ" > p t.get(m2,m1) #=> "" > m1.set(m1.id + '+1chars') > p t.index(m1) #=> "2.0" > p t.get(m1,m2) #=> "ABCDEFGHIJ" > ------------------------------------------------ > > And, I found bad implements in TkTextMark class. > Current definitions of TkTextMark#next and TkTextMark#previous are > ------------------------------------------------ > def next(index) > @t.tagid2obj(tk_call(@t.path, 'mark', 'next', index)) > end > > def previous(index) > @t.tagid2obj(tk_call(@t.path, 'mark', 'previous', index)) > end > ------------------------------------------------ > These should be followings. > ------------------------------------------------ > def next > @t.tagid2obj(tk_call(@t.path, 'mark', 'next', @id)) > end > > def previous > @t.tagid2obj(tk_call(@t.path, 'mark', 'previous', @id)) > end > ------------------------------------------------ > -- > Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) -- "It requires wisdom to understand wisdom: the music is nothing if the audience is deaf." - Walter Lippman