OSDN Git Service

Fix undo problems in the XML editor (issue #15901)
authorTor Norbye <tnorbye@google.com>
Fri, 15 Jul 2011 03:16:52 +0000 (20:16 -0700)
committerTor Norbye <tnorbye@google.com>
Fri, 15 Jul 2011 03:16:52 +0000 (20:16 -0700)
commit6a4ee36d267574fc94e5f87118f9a15d8d87abf5
tree4ed115afde327b077a53087de448cdd18de0f756
parent271993a2368361fb1f67ea9c1388a352e9df43f5
Fix undo problems in the XML editor (issue #15901)

We've had a recurring problem where in difficult-to-reproduce
circumstances the Undo button doesn't seem to work: After making some
edits like dropping a button, each press of the Undo button will each
individual edit of the compound operation, such as undoing each
attribute set, each element add, and so on -- just as if the entire
edit operation did not run under an undo lock.

This changeset fixes this issue - or at least one scenario of it
(tracked in http://code.google.com/p/android/issues/detail?id=15901 )

It turns out that Eclipse in some cases decides to "cancel" the current
Undo operation. This is done in reaction to selection changes, and the
logic for that is related to a user using a form editor to switch
between various attribute fields, and expecting each text field edit
to be separate. In the above issue I've listed a thread dump which
shows one such cancellation which is definitely not desirable.

To fix this bug we add a workaround: In our code which sets up the
undo recording, we call "beginRecording" -repeatedly- (say 4 times).
Since undo units are allowed to be nested, this means we're nesting
our own undos 4 times, and when we're finished with the editing
operation we simply call endRecording a corresponding number of
times. This means that when the offending code comes around and calls
StructuredTextUndoManager.forceEndOfPendingCommand it will subtract
the command count by one, but we'll still be in one of our nested
contexts (and the editor does allow extra endRecording calls to be
called).

Change-Id: Ic4dde029efcb18def3c9daa5d3676c49a815d804
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidXmlEditor.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gre/RulesEngine.java