mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-15 01:25:42 -05:00
Adds diff with next command Fixes #45 - Keyboard Shortcut collision with Project Manager Preps v2.11.2
61 lines
1.6 KiB
TypeScript
61 lines
1.6 KiB
TypeScript
|
|
'use strict';
|
|
import { commands, Disposable, TextEditor, window } from 'vscode';
|
|
import { BuiltInCommands } from './constants';
|
|
|
|
export class ActiveEditorTracker extends Disposable {
|
|
|
|
private _disposable: Disposable;
|
|
private _resolver: (value?: TextEditor | PromiseLike<TextEditor>) => void;
|
|
|
|
constructor() {
|
|
super(() => this.dispose());
|
|
|
|
this._disposable = window.onDidChangeActiveTextEditor(e => this._resolver && this._resolver(e));
|
|
}
|
|
|
|
dispose() {
|
|
this._disposable && this._disposable.dispose();
|
|
}
|
|
|
|
async awaitClose(timeout: number = 500): Promise<TextEditor> {
|
|
this.close();
|
|
return this.wait(timeout);
|
|
}
|
|
|
|
async awaitNext(timeout: number = 500): Promise<TextEditor> {
|
|
this.next();
|
|
return this.wait(timeout);
|
|
}
|
|
|
|
async close(): Promise<{}> {
|
|
return commands.executeCommand(BuiltInCommands.CloseActiveEditor);
|
|
}
|
|
|
|
async next(): Promise<{}> {
|
|
return commands.executeCommand(BuiltInCommands.NextEditor);
|
|
}
|
|
|
|
async wait(timeout: number = 500): Promise<TextEditor> {
|
|
const editor = await new Promise<TextEditor>((resolve, reject) => {
|
|
let timer: any;
|
|
|
|
this._resolver = (editor: TextEditor) => {
|
|
if (timer) {
|
|
clearTimeout(timer as any);
|
|
timer = 0;
|
|
resolve(editor);
|
|
}
|
|
};
|
|
|
|
timer = setTimeout(() => {
|
|
resolve(window.activeTextEditor);
|
|
timer = 0;
|
|
}, timeout) as any;
|
|
});
|
|
this._resolver = undefined;
|
|
return editor;
|
|
}
|
|
}
|
|
|