How can I keep undo history after saving on Visual Studio Code

做~自己de王妃 提交于 2020-05-10 07:09:09

问题


I'm using latest version of VS code (1.9.0).

After I undo (ctrl+z) something, and save the file (ctrl+s), then I cannot redo anymore (ctrl+y).

I would like to go back and forth during the editor is running same as Sublime or other editor. Can anyone solve this problem? Thank you.


回答1:


Undo/redo on

  • a kept open file

    That normally should work. If not, it could be an issue with one of your installed extensions. Try to start Visual Studio Code on a terminal/command line with

    code --disable-extensions
    

    Credits: Issue comment from Benjamin Pasero

  • a reopened file

    It's an unsolved bug (issue #7169). Vote & give feedback in this Github issue to help solving it. The VSCode developers track Github reactions to prioritize the work.

  • a saved as file

    Also an unsolved bug (issue #17977).




回答2:


For people getting to this question that want to disable the persistence of the undo stack after a file is closed, this too appears to be coming to v1.45.

See https://github.com/microsoft/vscode/issues/94778 and https://github.com/microsoft/vscode/pull/96317 and v1.45 Release Notes:

"files.restoreUndoStack": false

Set to false to disable undo stack items after a file is closed. the default is true.




回答3:


Hope this will work.

shift + command + z 

It will redo what you expected in Sublime Text (command + y )




回答4:


It's now a feature in the latest version :)

https://code.visualstudio.com/updates/v1_44#_keep-undo-stack-when-reopening-files




回答5:


The problem is confirmed in microsoft/vscode issue 10932 "Undo stack lost" (and linked to the aforementioned issue 7169, as part of the undo/redo issues)

We loose the undo stack very easily when leaving a dirty file in a tab (not visible) and then saving the dirty file:

  • open some tabs and make them dirty
  • wait for a few seconds
  • press "Save All"
  • go to those tabs that where not visible and try to undo
    => you cannot undo

For an opened file, it was solved in VSCode 1.5.0 (Sept. 2016) with commit b872e3d

But for a reopened file, VSCode 1.44 (March 2020) does address the issue, which is listed in the Iteration Plan for March 2020, and assigned to Alexandru Dima: see release notes

Keep Undo stack when reopening files

VS Code will now keep the Undo/Redo stack of a file when the file is closed. When the file is reopened, if its contents hasn't changed since it was closed, the Undo/Redo stack will be restored.

This is very useful if you limit the number of open editors with the workbench.editor.limit.value setting or you accidentally close a file you are working on.



来源:https://stackoverflow.com/questions/42020489/how-can-i-keep-undo-history-after-saving-on-visual-studio-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!