Sublime Forum

How can I call view.replace() without adding to the edit history?

#1

I’m calling view.replace(), and there is absolutely zero reason for it to ever show up in the edit history or be undone by the user. Doing so would create a bad user experience and likely cause them to accidentally undo only some of the changes and leave their document in a messed up state. How can I replace something in the view without adding to the edit history?

1 Like

#2

You can’t edit the document without affecting the undo/redo history, otherwise that functionality could not work. (Consider what would happen if a user made a change to the text you’re replacing).

What you probably want to do instead is group your text editing together. You can do this by doing all text editing from within a TextCommand. Alternatively if you’re adding/removing text you don’t want the user to edit consider using phantoms.

0 Likes

#3

The only possible way to achieve the functionality of my plugin is by having 2 separate commands, one is ran on a mouse button down, the other is ran on the mouse button release. So the edits can’t even be grouped into 1.

The contents of the buffer are the exact same before and after the 2 commands are ran, nothing is changed. And in between these 2 commands, I’m setting the buffer to read-only so that the user cannot change anything. And I’m also listening to every possible event to revert the changes in case they try to do something sneaky like close the window or run a command while they’re holding down the mouse button.

I also don’t think phantoms will work since the user will be selecting (but not editing) the text that I’m adding.

And run_command(‘undo’) doesn’t seem to work from within another command.

Some possible ways the API could be changed to make my plugin work correctly:

  • Let us skip the edit history
  • Make drag_select fire a command when it’s finished
  • Have on_selection_modified triggered BEFORE it’s actually modified
  • Let us disable automatic viewport scrolling when a selection is made
0 Likes

#4

Can you be more specific as to what your plugin is supposed to do?

0 Likes