Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Range of characters changed by edit undo
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



Report this thread to moderator Post Follow-up to this message
Old Post
Francois Vogel
06-05-05 01:57 AM


Re: Range of characters changed by edit undo
Hmm, 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



Report this thread to moderator Post Follow-up to this message
Old Post
Francois Vogel
06-05-05 01:56 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Tcl archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:42 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.