-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Fixed undo issue given in #2545 #2547
Conversation
Travis tests have failedHey @Chillee, Node.js: 8if [[ $(git diff-index HEAD --) ]]; then git diff; echo "Prettier Failed. Run `gulp` or `gulp forceprettier`"; exit 1; fi
|
Why? Edit: Looking at the code answered my question. Thanks also for the explanation @Chillee |
@jpoon When we close a file, we delete its handler from This caused us to initialize the undo history of the closed file with the text of the current file. Then, when you reopened that file, pressing undo would set you to the text of the other file. So, in this repro: #2545
|
@@ -30,7 +30,7 @@ let extensionContext: vscode.ExtensionContext; | |||
let previousActiveEditorId: EditorIdentity = new EditorIdentity(); | |||
|
|||
export async function getAndUpdateModeHandler(): Promise<ModeHandler> { | |||
const [prevHandler] = await ModeHandlerMap.getOrCreate(previousActiveEditorId.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can change this to a create
function, but I can do that refactor in a later commit.
src/mode/modeHandlerMap.ts
Outdated
@@ -16,6 +16,11 @@ class ModeHandlerMapImpl { | |||
return [modeHandler, isNew]; | |||
} | |||
|
|||
async get(key: string): Promise<ModeHandler | null> { | |||
let modeHandler = this.modeHandlerMap[key]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can probably do this all in one line.
Oh man what a hero! |
I agree with your conclusion, too. The ModeHandler stuff is a mess and has been responsible for more bugs than I could count. Worst part is, the biggest benefit of ModeHandler is per-file state, and I can't even remember why we need that. Nearly everything is per-project. |
Because you might be in insert mode in one file and another file be in visual? What do you mean per-project, there is definitely a need for per-file state... |
@Chillee, you're amazing. |
src/mode/modeHandlerMap.ts
Outdated
@@ -16,6 +16,10 @@ class ModeHandlerMapImpl { | |||
return [modeHandler, isNew]; | |||
} | |||
|
|||
async get(key: string): Promise<ModeHandler | null> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this actually return a promise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... No
@Chillee ok to merge? |
Yep! |
I'll cut a release for it. |
great guys! |
Thanks to @Diadlo for this repro. #2545.
Basically, we don't always want to create a
prevHandler
even if it doesn't exist. To be honest, this code is messy and I'd like to rewrite it entirely, if it wasn't for the fact that this kind of frail code is hard to test.This should fix many of the reports given in #2007. However, the first reports of the issue started before this repro was introduced. That suggests to me that there's actually 2 separate bugs. One where the file gets replaced by another file (issue 1), and one where the file actually drops back to an earlier undo state (issue 2).
Issue 1 was introduced around January 12th in this seemingly innocuous commit: c050066 .
The first report of this (replaced with another file is here): #2007 (comment) Many of the following comments were also expressing this issue.
However, the first report of issue 2 were given here: #928 The issue is slightly confused by the fact that the initial bug that @octref reports is a much more innocuous "Certain VSCode actions aren't given their own undo stop", while issue 2 is really "VSCodeVim is wiping out a ton of work". The first real report of issue 2 appears to be #928 (comment), on July 26th. I believe that this bug was likely introduced by this commit: #1629 on May 3rd.
This commit fixes issue 1. More work is needed to locate the cause of issue 2.
@jpoon @johnfn @xconverge @rebornix