Mark D has written:
Thanks for the code. It's very well written and has saved me a lot of time starting from scratch. I'm in the process of converting this code to actionscript and using it in a Flex application I'm working on. My application is a kind of rich text editor.
Things are going well, but I'm starting to think that I'm using transactions in a way that you may not have intended to, and I was wondering if you could give me your opinion on it.
In my case, when you type a character, one of several actions can occur depending on different things. For instance, inserting a text node with a value, or if the current node is currently a text node, adding a character to it and lastly moving the
caret position to after the character.
The way I implemented this is that I made actions for adding nodes, removing nodes, inserting characters into existing text nodes, and lastly moving the caret.
I made use of the transaction and created a transaction at the highest level in my code as possible, basically in the keypress handler. That way I didn't have to concern myself with all the different permutations the code took when handling keypress.
All I cared about was at the end that if you undid the action, it would undo everything that was created during that keypress.
This works fine, however, it totally disables the "merging" aspect of the framework. It seems that the multiAction used in transactions will never attempt to merge. The tryToMerge method returns false.
I can kind of see why you did it this way since the "rules" for merging multiactions may be specific to the application.
I'm considering altering this portion of the code to somehow iterate through the children in some systematic way to determine if things can be merged, but I have quite figured out how I'm going to do this.
One way is to just look at the last guy in the multiaction, but that won't help me since for me that's usually a move caret action. I need to look one more back into the multiaction to find the "insert text node" or the "insert character
into a text node" actions. In this case subsequent insert characters should merge with this. This starts to get complicated though so I wonder if I'm looking at this the wrong way.
If you have any insight into this, I would be interested to hear it.