Vim: Clean undo history if the content changed from Disk

Created on 30 Aug 2016  路  6Comments  路  Source: VSCodeVim/Vim

Please _thumbs-up_ 馃憤 this issue if it personally affects you! You can do this by clicking on the emoji-face on the top right of this post. Issues with more thumbs-up will be prioritized.


What did you do?

Open a Git repository in VS Code, open an out-dated file. Use git command to sync latest code from terminal. Then press u in the editor.

What did you expect to happen?

Nothing.

What happened instead?

The file reverts back the outdated version.

  • VSCode Version: 0.1.7
  • VsCodeVim Version: 1.5.0-Insiders
  • OS: OSX
help wanted kinbug sizM

Most helpful comment

screen shot 2016-09-01 at 12 20 01 am

@johnfn you are absolutely right. I just made a couple of tests and we can use e.document.isDirty property to check if the change is from an external source (false) or from vscode itself (true).

The only thing is that vscode api has a bug! In the image above, i have made a change using vscode (an internal change) and when the onDidTextDocumentChanged event is fired, it has the wrong value for isDirty. It should be true but it's false. Clearly there is a timing issue in vscode codebase between when the isDirty flag is set and when registered callbacks are fired.

What do you think? should i send a PR using isDirty and working around vscode api bug to clear the history?

All 6 comments

This one is definitely very annoying. One of my top priority items.

screen shot 2016-08-31 at 6 00 14 pm

@johnfn I was playing with events that are emitted by vscode Api. There seems to be no Api explicitly designed for notifications on git file changes, however i found out that when you sync files by git commands vscode.workspace.onDidChangeTextDocument will be triggered twice and the second time itsdoucment.uri.scheme == "git-index".
As far as i have tested in all other cases it's always scheme == "file" except when you issue a git command like git checkout branch-name or git merge branch-name.

Is it in your opinion Ok to use this event with scheme == "git-index" to clear the history?

@aminroosta the bigger problem here isn't just a git branch switch, it's any type of file change external to VSCode. While detecting branch changes is good, ideally we could detect all external file changes.

screen shot 2016-09-01 at 12 20 01 am

@johnfn you are absolutely right. I just made a couple of tests and we can use e.document.isDirty property to check if the change is from an external source (false) or from vscode itself (true).

The only thing is that vscode api has a bug! In the image above, i have made a change using vscode (an internal change) and when the onDidTextDocumentChanged event is fired, it has the wrong value for isDirty. It should be true but it's false. Clearly there is a timing issue in vscode codebase between when the isDirty flag is set and when registered callbacks are fired.

What do you think? should i send a PR using isDirty and working around vscode api bug to clear the history?

Wow, very nice detective work @aminroosta. I'm completely fine with mitigating it in VSCodeVim till it gets fixed in VSCode.

@johnfn @rebornix there is one more issue. Undo command marks the file as dirty even when all changes are reversed. It should revert to version 1 of the document that way I think vscode will not mark it as dirty.

Was this page helpful?
0 / 5 - 0 ratings