From d502694ba60f3573e103f657fdaabeb575ef49a7 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 1 Mar 2017 14:20:01 -0500 Subject: [PATCH] Fixes 'Compare with *' commands failing w/ no active editor --- src/commands/diffLineWithPrevious.ts | 14 +++++++------- src/commands/diffLineWithWorking.ts | 14 +++++++------- src/commands/diffWithPrevious.ts | 18 +++++++++--------- src/commands/diffWithWorking.ts | 14 +++++++------- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/commands/diffLineWithPrevious.ts b/src/commands/diffLineWithPrevious.ts index 9bd38d6..88aeeff 100644 --- a/src/commands/diffLineWithPrevious.ts +++ b/src/commands/diffLineWithPrevious.ts @@ -1,26 +1,26 @@ 'use strict'; -import { commands, TextEditor, TextEditorEdit, Uri, window } from 'vscode'; -import { Commands, EditorCommand } from './commands'; +import { commands, TextEditor, Uri, window } from 'vscode'; +import { ActiveEditorCommand, Commands } from './commands'; import { BuiltInCommands } from '../constants'; import GitProvider, { GitCommit, GitUri } from '../gitProvider'; import { Logger } from '../logger'; import * as path from 'path'; -export class DiffLineWithPreviousCommand extends EditorCommand { +export class DiffLineWithPreviousCommand extends ActiveEditorCommand { constructor(private git: GitProvider) { super(Commands.DiffLineWithPrevious); } async execute(editor: TextEditor): Promise; - async execute(editor: TextEditor, edit: TextEditorEdit, uri: Uri): Promise; - async execute(editor: TextEditor, edit?: TextEditorEdit, uri?: Uri, commit?: GitCommit, line?: number): Promise { + async execute(editor: TextEditor, uri: Uri): Promise; + async execute(editor: TextEditor, uri?: Uri, commit?: GitCommit, line?: number): Promise { if (!(uri instanceof Uri)) { - if (!editor.document) return undefined; + if (!editor || !editor.document) return undefined; uri = editor.document.uri; } - line = line || editor.selection.active.line; + line = line ||(editor && editor.selection.active.line) || 0; let gitUri = GitUri.fromUri(uri, this.git); if (!commit || GitProvider.isUncommitted(commit.sha)) { diff --git a/src/commands/diffLineWithWorking.ts b/src/commands/diffLineWithWorking.ts index dd3af86..17447cb 100644 --- a/src/commands/diffLineWithWorking.ts +++ b/src/commands/diffLineWithWorking.ts @@ -1,24 +1,24 @@ 'use strict'; -import { commands, TextEditor, TextEditorEdit, Uri, window } from 'vscode'; -import { Commands, EditorCommand } from './commands'; +import { commands, TextEditor, Uri, window } from 'vscode'; +import { ActiveEditorCommand, Commands } from './commands'; import GitProvider, { GitCommit, GitUri } from '../gitProvider'; import { Logger } from '../logger'; -export class DiffLineWithWorkingCommand extends EditorCommand { +export class DiffLineWithWorkingCommand extends ActiveEditorCommand { constructor(private git: GitProvider) { super(Commands.DiffLineWithWorking); } async execute(editor: TextEditor): Promise; - async execute(editor: TextEditor, edit: TextEditorEdit, uri: Uri): Promise; - async execute(editor: TextEditor, edit?: TextEditorEdit, uri?: Uri, commit?: GitCommit, line?: number): Promise { + async execute(editor: TextEditor, uri: Uri): Promise; + async execute(editor: TextEditor, uri?: Uri, commit?: GitCommit, line?: number): Promise { if (!(uri instanceof Uri)) { - if (!editor.document) return undefined; + if (!editor || !editor.document) return undefined; uri = editor.document.uri; } - line = line || editor.selection.active.line; + line = line || (editor && editor.selection.active.line) || 0; if (!commit || GitProvider.isUncommitted(commit.sha)) { const gitUri = GitUri.fromUri(uri, this.git); diff --git a/src/commands/diffWithPrevious.ts b/src/commands/diffWithPrevious.ts index 79232d0..0ca255a 100644 --- a/src/commands/diffWithPrevious.ts +++ b/src/commands/diffWithPrevious.ts @@ -1,30 +1,30 @@ 'use strict'; import { Iterables } from '../system'; -import { commands, Range, TextEditor, TextEditorEdit, Uri, window } from 'vscode'; -import { Commands, EditorCommand } from './commands'; +import { commands, Range, TextEditor, Uri, window } from 'vscode'; +import { ActiveEditorCommand, Commands } from './commands'; import { BuiltInCommands } from '../constants'; import GitProvider, { GitCommit, GitUri } from '../gitProvider'; import { Logger } from '../logger'; import * as moment from 'moment'; import * as path from 'path'; -export class DiffWithPreviousCommand extends EditorCommand { +export class DiffWithPreviousCommand extends ActiveEditorCommand { constructor(private git: GitProvider) { super(Commands.DiffWithPrevious); } async execute(editor: TextEditor): Promise; - async execute(editor: TextEditor, edit: TextEditorEdit, uri: Uri): Promise; - async execute(editor: TextEditor, edit: TextEditorEdit, uri: Uri, commit: GitCommit, range?: Range): Promise; - async execute(editor: TextEditor, edit: TextEditorEdit, uri: Uri, commit: GitCommit, line?: number): Promise; - async execute(editor: TextEditor, edit?: TextEditorEdit, uri?: Uri, commit?: GitCommit, rangeOrLine?: Range | number): Promise { + async execute(editor: TextEditor, uri: Uri): Promise; + async execute(editor: TextEditor, uri: Uri, commit: GitCommit, range?: Range): Promise; + async execute(editor: TextEditor, uri: Uri, commit: GitCommit, line?: number): Promise; + async execute(editor: TextEditor, uri?: Uri, commit?: GitCommit, rangeOrLine?: Range | number): Promise { if (!(uri instanceof Uri)) { - if (!editor.document) return undefined; + if (!editor || !editor.document) return undefined; uri = editor.document.uri; } - let line = editor.selection.active.line; + let line = (editor && editor.selection.active.line) || 0; if (typeof rangeOrLine === 'number') { line = rangeOrLine || line; rangeOrLine = undefined; diff --git a/src/commands/diffWithWorking.ts b/src/commands/diffWithWorking.ts index 6e8b79a..181a61b 100644 --- a/src/commands/diffWithWorking.ts +++ b/src/commands/diffWithWorking.ts @@ -1,27 +1,27 @@ 'use strict'; import { Iterables } from '../system'; -import { commands, TextEditor, TextEditorEdit, Uri, window } from 'vscode'; -import { Commands, EditorCommand } from './commands'; +import { commands, TextEditor, Uri, window } from 'vscode'; +import { ActiveEditorCommand, Commands } from './commands'; import { BuiltInCommands } from '../constants'; import GitProvider, { GitCommit, GitUri } from '../gitProvider'; import { Logger } from '../logger'; import * as path from 'path'; -export class DiffWithWorkingCommand extends EditorCommand { +export class DiffWithWorkingCommand extends ActiveEditorCommand { constructor(private git: GitProvider) { super(Commands.DiffWithWorking); } async execute(editor: TextEditor): Promise; - async execute(editor: TextEditor, edit: TextEditorEdit, uri: Uri): Promise; - async execute(editor: TextEditor, edit?: TextEditorEdit, uri?: Uri, commit?: GitCommit, line?: number): Promise { + async execute(editor: TextEditor, uri: Uri): Promise; + async execute(editor: TextEditor, uri?: Uri, commit?: GitCommit, line?: number): Promise { if (!(uri instanceof Uri)) { - if (!editor.document) return undefined; + if (!editor || !editor.document) return undefined; uri = editor.document.uri; } - line = line || editor.selection.active.line; + line = line || (editor && editor.selection.active.line) || 0; if (!commit || GitProvider.isUncommitted(commit.sha)) { const gitUri = GitUri.fromUri(uri, this.git);