Ace Editor Pause/Disable UndoManager

2019-09-11 01:32发布

问题:

  • Is there any way to remove specific stack value from UndoManager

OR

  • any function to pause/disable and start/enable UndoManager again.

I want not to push specific data to UndoManager's stack.

回答1:

It is not possible to simply not push deltas to the stack, since in that case undoing previous deltas won't be possible, you need to also transform the deltas around skipped delta. Say if you have a document "xyz" to which {insert, 2, "a"} is applied to obtain "xyaz" and then {insert, 1, "b"} to get "xbyaz". Now to undo the first edit but keep second one you need to apply {delete, 2+1, "a"}. The algorithm for doing this is not very complex, but it requires to handle many branches, so can get hairy. Ace doesn't provide an api for this atm.