Code Comments
Programming Forum and web based access to our favorite programming groups.Hi all, I'm making use of the edit undo capability of the text widget. Iwould like to know which range(s) of characters were modified by an undo. In other words, I would like to know at which index in the text the internal undo stuff started to insert or delete characters, and at which index it stopped. I tried to use a tag the following way (simplified, should work only to undo a delete near the middle of the text): $w tag add unchanged 1.0 end event generate $w <<Undo>> set range1 [$w tag nextrange unchanged 1.0] set i1 [lindex $range1 1] set range2 [$w tag nextrange unchanged $i1] set i2 [lindex $range2 0] $w tag remove unchanged 1.0 end # here I do my stuff with the characters that were changed, e.g. colorize them, and I thought they would be located between $i1 and $i2 But this does not work since apparently the characters inserted by undo also has the "unchanged" tag (surprising!), which ends up with $range1 being the full text and $range2 being empty. What else could I do? It would be nice if [.t edit undo] would return this range, but maybe there is another way. Thanks for any hint, Francois
Post Follow-up to this messageHmm, I found the following implementation, that seems to work: set bef [$w get 1.0 end] event generate $w <<Undo>> set aft [$w get 1.0 end] set pref [commonPrefix $bef $aft] set i1 [$w index "1.0 + [string length $pref] chars"] set rbef [srevert $bef] set raft [srevert $aft] set pref [commonPrefix $rbef $raft] set i2 [$w index "end - [string length $pref] chars"] # here colorization between $i1 and $i2 Procs srevert and commonPrefix can be found at http://wiki.tcl.tk/44 (additional string functions). I was a bit afraid wrt performance, but it seems to be quite reasonable even for large (15000 lines) text widget content. If anybody has a better idea, please share. Francois
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.