From 360cdac3cc8beb2ad0006e180e364b2cbff8efbf Mon Sep 17 00:00:00 2001 From: James Tsai Date: Mon, 13 Jul 2020 22:49:33 +0800 Subject: [PATCH] Create code snippet with whole file when not selecting code section --- src/commands/snippet.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/commands/snippet.ts b/src/commands/snippet.ts index 2a0397a..454696a 100644 --- a/src/commands/snippet.ts +++ b/src/commands/snippet.ts @@ -8,15 +8,16 @@ export function registerSnippetCommands(context: vscode.ExtensionContext) { vscode.window.showInformationMessage('Please login first.'); return; } - + const editor = vscode.window.activeTextEditor; + let text: string; if (editor.selection.isEmpty) { - vscode.window.showInformationMessage('The code block is empty. Please select a range of text first.'); - return; + text = vscode.window.activeTextEditor.document.getText(); + } else { + const textRange = new vscode.Range(editor.selection.start.line, editor.selection.start.character, editor.selection.end.line, editor.selection.end.character); + text = vscode.window.activeTextEditor.document.getText(textRange); } - const textRange = new vscode.Range(editor.selection.start.line, editor.selection.start.character, editor.selection.end.line, editor.selection.end.character); - const text = vscode.window.activeTextEditor.document.getText(textRange); const filePath = vscode.workspace.asRelativePath(editor.document.uri.fsPath); const snippet = `---