Skip to content

Commit

Permalink
VSCodeVim#3455: Compare EditorIdentity when handling window.onDidCha…
Browse files Browse the repository at this point in the history
…ngeTextEditorSelection.
  • Loading branch information
coddingtonbear committed Feb 28, 2019
1 parent a8e9b71 commit 7d97e7a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 3 additions & 1 deletion extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,11 @@ export async function activate(context: vscode.ExtensionContext) {
context,
vscode.window.onDidChangeTextEditorSelection,
async (e: vscode.TextEditorSelectionChangeEvent) => {
const eventEditorIdentity = new EditorIdentity(e.textEditor);
const activeEditorId = new EditorIdentity(vscode.window.activeTextEditor);
if (
vscode.window.activeTextEditor === undefined ||
e.textEditor.document !== vscode.window.activeTextEditor.document
!eventEditorIdentity.isEqual(activeEditorId)
) {
// we don't care if there is no active editor
// or user selection changed in a paneled window (e.g debug console/terminal)
Expand Down
14 changes: 12 additions & 2 deletions src/editorIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,30 @@ import * as vscode from 'vscode';

export class EditorIdentity {
private _fileName: string;
private _viewColumn: number;

constructor(textEditor?: vscode.TextEditor) {
this._fileName = (textEditor && textEditor.document && textEditor.document.fileName) || '';
this._viewColumn = (textEditor && textEditor.viewColumn) || vscode.ViewColumn.One;
}

get fileName() {
return this._fileName;
}

get viewColumn() {
return this._viewColumn;
}

get identifier() {
return this.fileName + this.viewColumn;
}

public isEqual(other: EditorIdentity): boolean {
return this.fileName === other.fileName;
return this.identifier === other.identifier;
}

public toString() {
return this.fileName;
return this.identifier;
}
}

0 comments on commit 7d97e7a

Please sign in to comment.