mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-20 09:45:36 -05:00
Refactors commit quick pick commands
Splits showQuickCommitDetails into showQuickCommitDetails and showQuickCommitFileDetails Adds closeUnchangedFiles command Adds openChangedFiles command Adds diffDirectory command Adds contextual description to the `go back` commands Fixes #44 by adding a warning message about Git version requirements Fixes intermittent errors when adding active line annotations Fixes intermittent errors when opening multiple files via quick picks Updates dependencies Preps v2.11.0
This commit is contained in:
59
src/activeEditorTracker.ts
Normal file
59
src/activeEditorTracker.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
|
||||
'use strict';
|
||||
import { commands, Disposable, TextEditor, window } from 'vscode';
|
||||
|
||||
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('workbench.action.closeActiveEditor');
|
||||
}
|
||||
|
||||
async next(): Promise<{}> {
|
||||
return commands.executeCommand('workbench.action.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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user