Skip to content

Commit

Permalink
Merge pull request #3041 from shawnaxsom/feature/jump-tracker-close-f…
Browse files Browse the repository at this point in the history
…ile-on-jump-fixes

Fixed Jump Tracker jumps when jumping from a file that auto closes
  • Loading branch information
Chillee authored Sep 12, 2018
2 parents 3602e68 + 55d1f03 commit b8e42aa
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { CompositionState } from './src/state/compositionState';
const globalState = new GlobalState();
let extensionContext: vscode.ExtensionContext;
let previousActiveEditorId: EditorIdentity | null = null;
let lastClosedModeHandler: ModeHandler | null = null;

interface ICodeKeybinding {
after?: string[];
Expand Down Expand Up @@ -166,18 +167,30 @@ export async function activate(context: vscode.ExtensionContext) {
return;
}

const mhPrevious: ModeHandler | null = previousActiveEditorId
? ModeHandlerMap.get(previousActiveEditorId.toString())
: null;
// Track the closed editor so we can use it the next time an open event occurs.
// When vscode changes away from a temporary file, onDidChangeActiveTextEditor first twice.
// First it fires when leaving the closed editor. Then onDidCloseTextDocument first, and we delete
// the old ModeHandler. Then a new editor opens.
//
// This also applies to files that are merely closed, which allows you to jump back to that file similarly
// once a new file is opened.
lastClosedModeHandler = mhPrevious || lastClosedModeHandler;

if (vscode.window.activeTextEditor === undefined) {
return;
}

taskQueue.enqueueTask(async () => {
if (vscode.window.activeTextEditor !== undefined) {
const mhPrevious: ModeHandler | null = previousActiveEditorId
? ModeHandlerMap.get(previousActiveEditorId.toString())
: null;

const mh: ModeHandler = await getAndUpdateModeHandler();

await mh.updateView(mh.vimState, { drawSelection: false, revealRange: false });

globalState.jumpTracker.handleFileJump(
mhPrevious ? Jump.fromStateNow(mhPrevious.vimState) : null,
lastClosedModeHandler ? Jump.fromStateNow(lastClosedModeHandler.vimState) : null,
Jump.fromStateNow(mh.vimState)
);
}
Expand Down

0 comments on commit b8e42aa

Please sign in to comment.