The code sample doesnât really help me much, but I can suggest the following:
Always use the edit
object you get handed in the TextCommandâs run
method and then forward that explicitly to synchronous function calls if necessary.
The reason is that edit objects are opened and closed internally before and after your run
method is called and behavior will be unpredictable if you use the edit object after it has been closed already. Furthermore, you can nest TextCommands (i.e. call a text command within a text command) and every change made during the existance of the outer edit object will get grouped into it for undoing purposes, which means there is an implicit hierarchy between edit objects. I do not know what happens when you use the outer edit object while an inner object still exists.
Maybe this can help you spot the actual problem because there is no real error description included in your post (besides âdoesnât workâ).