From 514a7c60aa739abc09742959dae7c25962eac73a Mon Sep 17 00:00:00 2001 From: Ilya Golovin Date: Thu, 25 Aug 2022 00:57:31 +0300 Subject: [PATCH 1/2] Fix: make git commands work from keyboard --- extensions/git/src/commands.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 00827778a0ef5..01f6331afd5a8 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -1717,7 +1717,11 @@ export class CommandCenter { @command('git.commitMessageAccept') async commitMessageAccept(arg?: Uri): Promise { - if (!arg) { return; } + if (!arg) { + const activeEditor = window.activeTextEditor; + if (!activeEditor) { return; } + arg = activeEditor.document.uri; + } // Close the tab this._closeEditorTab(arg); @@ -1725,11 +1729,15 @@ export class CommandCenter { @command('git.commitMessageDiscard') async commitMessageDiscard(arg?: Uri): Promise { - if (!arg) { return; } + if (!arg) { + const activeEditor = window.activeTextEditor; + if (!activeEditor) { return; } + arg = activeEditor.document.uri; + } // Clear the contents of the editor const editors = window.visibleTextEditors - .filter(e => e.document.languageId === 'git-commit' && e.document.uri.toString() === arg.toString()); + .filter(e => e.document.languageId === 'git-commit' && e.document.uri.toString() === arg!.toString()); if (editors.length !== 1) { return; } From c99c3818fc45a81dede0f11e2ab4fd948facd969 Mon Sep 17 00:00:00 2001 From: Ilya Golovin Date: Thu, 8 Dec 2022 16:28:45 +0300 Subject: [PATCH 2/2] refactor: improve code style --- extensions/git/src/commands.ts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 01f6331afd5a8..a26f887c442c3 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -1717,11 +1717,8 @@ export class CommandCenter { @command('git.commitMessageAccept') async commitMessageAccept(arg?: Uri): Promise { - if (!arg) { - const activeEditor = window.activeTextEditor; - if (!activeEditor) { return; } - arg = activeEditor.document.uri; - } + if (!arg && !window.activeTextEditor) { return; } + arg ??= window.activeTextEditor!.document.uri; // Close the tab this._closeEditorTab(arg); @@ -1729,11 +1726,8 @@ export class CommandCenter { @command('git.commitMessageDiscard') async commitMessageDiscard(arg?: Uri): Promise { - if (!arg) { - const activeEditor = window.activeTextEditor; - if (!activeEditor) { return; } - arg = activeEditor.document.uri; - } + if (!arg && !window.activeTextEditor) { return; } + arg ??= window.activeTextEditor!.document.uri; // Clear the contents of the editor const editors = window.visibleTextEditors