Tk Source Code

View Ticket
Login
Ticket UUID: 1275237
Title: modified flag not managed when undoing certain text inserts
Type: Bug Version: obsolete: 8.4.11
Submitter: fvogel Created on: 2005-08-28 18:40:36
Subsystem: 18. [text] Assigned To: hobbs
Priority: 6 Severity:
Status: Closed Last Modified: 2014-02-19 21:42:12
Resolution: Fixed Closed By: hobbs
    Closed on: 2006-03-31 06:29:34
Description:
The modified flag of the text widget is not well managed 
by Tk when certain changes are undone.

Example 1 (works OK):
text .t -undo 1
pack .t
.t insert 1.0 "Hello world!   "
.t edit reset
.t edit modified false
.t insert 1.14 "Goodbye!"
puts [.t edit modified]
.t edit undo
puts [.t edit modified]

The output in the console is:
1
0
which is correct: the modified flag has been reset to 
false by the undo.

Example 2 (wrong results):
text .t -undo 1
pack .t
.t insert 1.0 "Hello world!   "
.t edit reset
.t edit modified false
.t insert 1.14 ""
puts [.t edit modified]
.t edit undo
puts [.t edit modified]

The only difference is that instead of 
inserting "Goodbye!" the script inserts an empty 
string "".

The output in the console is in this case:
1
1
i.e. the modified flag was not reset by the undo 
operation.

The undo has been correctly performed since a further .t 
edit undo spits:
nothing to undo

This problem therefore concerns only the modified flag.
User Comments: hobbs added on 2006-03-31 13:29:34:
Logged In: YES 
user_id=72656

I have commited to 8.4.13 with a change that doesn't do
anything in InsertChars is *string == '\0'.

fvogelnew1 added on 2006-03-20 02:33:12:
Logged In: YES 
user_id=1245417

Thanks,

Any chance to have it in the upcoming 8.4.13?

Francois

nobody added on 2006-03-18 22:53:20:
Logged In: NO 

Fixed in cvs HEAD by not touching undo/modified information when inserting 
empty strings.

fvogelnew1 added on 2006-03-18 20:21:21:
Logged In: YES 
user_id=1245417

Vince,

Did you try this patch or apply it to HEAD?

Francois

lgac added on 2005-12-28 17:41:08:
Logged In: YES 
user_id=316951

Patch 1391852 submitted to fix this. But as stated below, 
a better fix may be to bail out early if the string to be 
inserted is empty.

lgac added on 2005-12-28 17:28:31:
Logged In: YES 
user_id=316951

The problem is due to an assymmetry in the insert and 
delete of text. When an insert is done and undo is 
enabled, two commands are recorded on teh undo stack:
a delete command to undo the change, and an insert command 
to redo the change.
So when undoing an insert, the recorded delete command is 
executed. When the insert string is empty however, there 
will be nothing to delete, and the delete command will 
prematurely exit, before setting the modified flag 
correctly (in fact the isDirty flag needs to be 
decremented).
The result is that the modified flag (aka the isDirty 
flag) does not become zero, and the modified command still 
returns true although all changes have been undone.
I have made a patch that fixes the problem by not 
recording some thing on the undo stack is the string to 
insert is empty.
However a better fix may be to not do anything altogether 
when trying to insert an empty string (similar to doing 
nothing when both indices for a delete are identical). I 
was not sure however that there would be no sideeffects 
for this, so maybe someone can have a look at this? Vince?

vincentdarley added on 2005-09-07 16:49:47:
Logged In: YES 
user_id=32170

'fraid I don't know much about the modified/undo stuff --
that's not been part of the changes I've been dealing with
in the text widget. Particularly since this is in 8.4.x it's
even further removed. (Although I would imagine the same
problem is in 8.5.x).

Perhaps you should see if Ludwig (TIP#26 author) can take a
look.