Skip to content
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

clear history when content from disk is changed #703

Merged
merged 5 commits into from
Sep 3, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import * as vscode from 'vscode';
import * as util from './src/util';
import * as _ from "lodash";
import { showCmdLine } from './src/cmd_line/main';
import { ModeHandler } from './src/mode/modeHandler';
import { TaskQueue } from './src/taskQueue';
Expand Down Expand Up @@ -114,6 +115,15 @@ export async function activate(context: vscode.ExtensionContext) {

vscode.window.onDidChangeActiveTextEditor(handleActiveEditorChange, this);

vscode.workspace.onDidChangeTextDocument((event) => {
/* TODO: Remove setTimeout (https://github.com/Microsoft/vscode/issues/11339) */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you write a little documentation on why this is needed (isDirty not immediately set etc)

setTimeout(() => {
if (event.document.isDirty === false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose you are typing too fast to check a boolean through === :)

handleContentChangedFromDisk(event.document);
}
}, 0);
});

registerCommand(context, 'type', async (args) => {
if (!vscode.window.activeTextEditor) {
return;
Expand Down Expand Up @@ -217,6 +227,13 @@ async function handleKeyEvent(key: string): Promise<void> {
});
}

function handleContentChangedFromDisk(document : vscode.TextDocument) : void {
_.filter(modeHandlerToEditorIdentity, { "fileName" : document.fileName})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep the leading/trailing spaces consistent { "fileName" : document.fileName}

.forEach((modeHandler) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing about the brackets here :)

Copy link
Contributor Author

@aminroosta aminroosta Sep 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about them? @jpoon

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That you can remove the brackets around (modeHandler)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

screen shot 2016-09-03 at 3 44 12 am

@jpoon I saw other places are always using brackets even for a single argument, that's why i added those brackets 😄

modeHandler.vimState.historyTracker.clear();
});
}

async function handleActiveEditorChange(): Promise<void> {

// Don't run this event handler during testing
Expand Down
10 changes: 10 additions & 0 deletions src/history/historyTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,16 @@ export class HistoryTracker {
}

constructor() {
this._initialize();
}

public clear() {
this.historySteps = [];
this.currentHistoryStepIndex = 0;
this._initialize();
}

private _initialize() {
/**
* We add an initial, unrevertable step, which inserts the entire document.
*/
Expand Down
6 changes: 3 additions & 3 deletions src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ export class ModeHandler implements vscode.Disposable {
/**
* Filename associated with this ModeHandler. Only used for debugging.
*/
public filename: string;
public fileName: string;

private _caretDecoration = vscode.window.createTextEditorDecorationType(
{
Expand Down Expand Up @@ -491,7 +491,7 @@ export class ModeHandler implements vscode.Disposable {
constructor(filename = "") {
ModeHandler.IsTesting = Globals.isTesting;

this.filename = filename;
this.fileName = filename;

this._vimState = new VimState();
this._insertModeRemapper = new InsertModeRemapper(true);
Expand Down Expand Up @@ -532,7 +532,7 @@ export class ModeHandler implements vscode.Disposable {
return;
}

if (e.textEditor.document.fileName !== this.filename) {
if (e.textEditor.document.fileName !== this.fileName) {
return;
}

Expand Down