Skip to content

Commit

Permalink
Remove the optimization and detect if mightChangeDocument is miscon…
Browse files Browse the repository at this point in the history
…figured
  • Loading branch information
J-Fields committed Jan 1, 2020
1 parent 6a31768 commit c254b21
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/history/historyTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,14 @@ export class HistoryTracker {
*
* Determines what changed by diffing the document against what it
* used to look like.
*
* @returns true if a change was added
*/
public addChange(cursorPosition = [new Position(0, 0)]): void {
public addChange(cursorPosition = [new Position(0, 0)]): boolean {
const newText = this._getDocumentText();

if (newText === this.oldText) {
return;
return false;
}

// Determine if we should add a new Step.
Expand Down Expand Up @@ -495,6 +497,8 @@ export class HistoryTracker {

// A change has been made, reset the changelist navigation index to the end
this.changelistIndex = this.historySteps.length - 1;

return true;
}

/**
Expand Down
21 changes: 19 additions & 2 deletions src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,25 @@ export class ModeHandler implements vscode.Disposable {
if (this.vimState.alteredHistory) {
this.vimState.alteredHistory = false;
vimState.historyTracker.ignoreChange();
} else if (action.mightChangeDocument) {
vimState.historyTracker.addChange(this.vimState.cursorsInitialState.map(c => c.stop));
} else {
const addedChange = vimState.historyTracker.addChange(
this.vimState.cursorsInitialState.map(c => c.stop)
);
if (addedChange && !action.mightChangeDocument) {
const errorMsg = `Action '${action.toString()}' changed the document unexpectedly`;
const choice = await vscode.window.showErrorMessage(
`${errorMsg}! This is a bug - please report it.`,
'Report bug'
);
if (choice === 'Report bug') {
vscode.commands.executeCommand(
'vscode.open',
vscode.Uri.parse(
`https://github.com/VSCodeVim/Vim/issues/new?title=${errorMsg}&labels=bug`
)
);
}
}
}
}

Expand Down

0 comments on commit c254b21

Please sign in to comment.