4

I'm trying to develop a vscode extension that needs to access the vscode undo stack but I can't seem to find any documentation about this.

scroobius
  • 662
  • 2
  • 7
  • 25

1 Answers1

4

I do not see any way for extensions to directly access the undo stack. The undo stack is implemented in editStack.ts, but it isn't exposed in the API.

I also do not see any open issues requesting such access. I didn't search through closed issues though.

Some possible alternatives

The question How to see local history changes in Visual Studio Code? discusses a couple of extensions that provide access to old versions by keeping track themselves.

When invoking TextEditor.edit, you have the option of creating undo stops before and after.

Via executeCommand, it is possible to execute commands like undo, redo, and cursorUndo.

You can use workspace.onDidChangeTextDocument to monitor documents for changes in order to collect your own document history. However, it does not look like you can tell whether a given change also created an undo stop, nor whether the change was triggered by an undo or redo command.

That said, Issue #1431: Support onDidExecuteCommand, discussed in this answer of mine, should allow listening for invocation of undo and redo, but I haven't played with it at all.

Scott McPeak
  • 8,803
  • 2
  • 40
  • 79
  • Hey @Scott McPeak. Great Info here. And the options we have when invoking [`TextEditor.edit`](https://code.visualstudio.com/api/references/vscode-api#TextEditor.edit) `{undoStopAfter: false, undoStopBefore: false}` works for my purpose and can disable the undo. – Shady Jan 14 '22 at 10:27