-
Notifications
You must be signed in to change notification settings - Fork 29.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keep undo history even when file changes outside Code #2908
Comments
Indeed, the current handling of a file change on disk is to drop the old buffer and allocate everything fresh. I'm wondering what other editors do... fyi @bpasero |
Sublime considers the external modification as an entry in the history. So if you do one The problem with dropping the buffer is when you have an external process to monitor the files and for example format it. (i.e. |
Would indeed be very nice to preserve the undo history even for changes outside Code. |
This has saved me in Sublime before; I'd really like to see it in code. Scenario: Working with multiple repos in multiple terminals, VS Code used to edit files in one (still using the terminal for git operations). In a terminal for another repo I want to blow away any unstaged changes so I throw a |
This is the only thing that keeps me going back to atom or sublime. Would love to see this feature implemented. Is it in the pipeline or planned..? |
Agree, that feature in Sublime has been a life saver many times. |
Just blew away two hours of work by typing |
Damn it, accidentally ran |
Webstorm allows this as well, and is incredibly helpful at times. |
Almost a year now , undo history should be preserved. |
For the time being those in need can use "history" extension at marketplace. Although a workaround, works for time being in case files get replaced, for e.g. git checkouts or losing the stash. |
@aga5tya Do you mean xyz.local-history? |
@emyller, yes, that's the one. |
+1 |
+1 |
Any update on this? Are there any plans to implement it? |
+1 Just happened to me because I'm used to this behavior. Now to rewrite a few hours of code... 😞 |
I started looking into implementing this and have a few questions @waderyan @alexandrudima: Here is the place where we clear the history: https://github.com/Microsoft/vscode/blob/f07f89928b9ea8b54c3fcb4c105c2d28f55b12dc/src/vs/editor/common/model/editableTextModel.ts#L82 What is the appropriate way to push an edit operation rather than clear the history? I tried an initial naive approach of just putting the entire buffer onto the undo stack: protected _resetValue(newValue: ITextSource): void {
// super._resetValue(newValue); <-- If I call this, the model is changed without an edit operation, and an edit operation no longer makes sense.
this._commandManager.pushEditOperation(
[new Selection(1, 1, 1, 1)],
[EditOperation.replace(this.getFullModelRange(), newValue.lines.join(newValue.EOL))],
(inverseEditOperations: editorCommon.IIdentifiedSingleEditOperation[]) => [new Selection(1, 1, 1, 1)]
);
// Destroy my edit history and settings
// this._commandManager = new EditStack(this);
this._hasEditableRange = false;
this._editableRangeId = null;
this._trimAutoWhitespaceLines = null;
} But there are a few issues with pushing a new edit operation here.
Perhaps we need to override How do I push an edit operation, tell the model that it's unchanged, and what should the cursor state and cursorStateComputer be? |
@stringham thanks for looking into this 👍. The place to make the change is not in the model, within the A Perhaps the |
I just lost code from this as well. My previous editor (PHPStorm) handled this beautifully. Very disappointing that VS Code has no way to undo external changes. |
This is definitely a must have. I felt safe changing files outside as I used a use Sublime and ran into this today... |
+1 |
Any news? |
I'm also affected by this. Means I still need to use sublime for certain projects. |
yeah, this will be good. the undo function of sublime it's really a life saver |
+1 |
Thanks to @stringham , if all goes well with testing, this will make it into our August release. |
When we can expect this to be live as today I faced the same issue while trying tasks in vscode. I created a wrong task and boom, my file was changes and now I can not undo it at all. |
@akanshgulati AFAIK this has been live since September. I'm on version 1.18.0 and it works |
@rhymes I tried using |
@akanshgulati I don't know if it's the same problem. Try: open a text file with vscode, write something in it, open the same file with another editor, change the content, go back to vscode and you'll see the new content, do cmd - z and you should see the original content. It also works with "git checkout -- file.txt" in case you're working inside a git repository. |
When a file is being modified in Code, then an external process modifies something in the file, for example a code formatter, the modification is loaded instantly in Code, but all the history is lost.
Expected behavior would be to have the external modification, as one entry in the history.
Steps to reproduce:
1 - Start a new file in
VS Code
and start typing in the file, then save the file. Keep the file andVS Code
open.2 - Open the same file in another editor. Modify some thing and save.
3 - Go back to
VS Code
, there is not 'Undo' available.The text was updated successfully, but these errors were encountered: