Procházet zdrojové kódy

Fixes repo quickpick choices fail w/ no editors

main
Eric Amodio před 7 roky
rodič
revize
0d7633c78a
3 změnil soubory, kde provedl 33 přidání a 13 odebrání
  1. +20
    -1
      src/commands/commands.ts
  2. +8
    -7
      src/commands/showQuickCommitDetails.ts
  3. +5
    -5
      src/commands/showQuickFileHistory.ts

+ 20
- 1
src/commands/commands.ts Zobrazit soubor

@ -1,5 +1,5 @@
'use strict';
import { commands, Disposable, TextEditor, TextEditorEdit } from 'vscode';
import { commands, Disposable, TextEditor, TextEditorEdit, window } from 'vscode';
import { Commands } from '../constants';
export abstract class Command extends Disposable {
@ -31,4 +31,23 @@ export abstract class EditorCommand extends Disposable {
}
abstract execute(editor: TextEditor, edit: TextEditorEdit, ...args: any[]): any;
}
export abstract class ActiveEditorCommand extends Disposable {
private _disposable: Disposable;
constructor(command: Commands) {
super(() => this.dispose());
this._disposable = commands.registerCommand(command, this._execute, this);
}
dispose() {
this._disposable && this._disposable.dispose();
}
_execute(...args: any[]): any {
return this.execute(window.activeTextEditor, ...args);
}
abstract execute(editor: TextEditor, ...args: any[]): any;
}

+ 8
- 7
src/commands/showQuickCommitDetails.ts Zobrazit soubor

@ -1,22 +1,22 @@
'use strict';
import { Iterables } from '../system';
import { TextEditor, TextEditorEdit, Uri, window } from 'vscode';
import { EditorCommand } from './commands';
import { TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCommand } from './commands';
import { Commands } from '../constants';
import GitProvider, { GitCommit, GitUri } from '../gitProvider';
import { Logger } from '../logger';
import { CommandQuickPickItem, FileQuickPickItem } from './quickPickItems';
import { CommitQuickPick, CommitFilesQuickPick } from './quickPicks';
export default class ShowQuickCommitDetailsCommand extends EditorCommand {
export default class ShowQuickCommitDetailsCommand extends ActiveEditorCommand {
constructor(private git: GitProvider) {
super(Commands.ShowQuickCommitDetails);
}
async execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri, sha?: string, commit?: GitCommit, goBackCommand?: CommandQuickPickItem, options: { showFileHistory?: boolean } = { showFileHistory: true }) {
async execute(editor: TextEditor, uri?: Uri, sha?: string, commit?: GitCommit, goBackCommand?: CommandQuickPickItem, options: { showFileHistory?: boolean } = { showFileHistory: true }) {
if (!(uri instanceof Uri)) {
if (!editor.document) return undefined;
if (!editor || !editor.document) return undefined;
uri = editor.document.uri;
}
@ -24,9 +24,10 @@ export default class ShowQuickCommitDetailsCommand extends EditorCommand {
let repoPath = gitUri.repoPath;
let line = editor.selection.active.line;
if (!sha) {
const blameline = line - gitUri.offset;
if (!editor) return undefined;
const blameline = editor.selection.active.line - gitUri.offset;
if (blameline < 0) return undefined;
try {

+ 5
- 5
src/commands/showQuickFileHistory.ts Zobrazit soubor

@ -1,21 +1,21 @@
'use strict';
import { commands, TextEditor, TextEditorEdit, Uri, window } from 'vscode';
import { EditorCommand } from './commands';
import { commands, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCommand } from './commands';
import { Commands } from '../constants';
import GitProvider, { GitUri } from '../gitProvider';
import { Logger } from '../logger';
import { CommandQuickPickItem } from './quickPickItems';
import { FileCommitsQuickPick } from './quickPicks';
export default class ShowQuickFileHistoryCommand extends EditorCommand {
export default class ShowQuickFileHistoryCommand extends ActiveEditorCommand {
constructor(private git: GitProvider) {
super(Commands.ShowQuickFileHistory);
}
async execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri, maxCount?: number, goBackCommand?: CommandQuickPickItem) {
async execute(editor: TextEditor, uri?: Uri, maxCount?: number, goBackCommand?: CommandQuickPickItem) {
if (!(uri instanceof Uri)) {
if (!editor.document) return undefined;
if (!editor || !editor.document) return undefined;
uri = editor.document.uri;
}

Načítá se…
Zrušit
Uložit