From 7aaebf0332397be5f8412d44f6ea33cf1bfc7ec3 Mon Sep 17 00:00:00 2001 From: Henning Dieterichs Date: Mon, 24 Aug 2020 17:05:54 +0200 Subject: [PATCH] Selects expression enclosed in backticks when nothing is selected and shift+F1 is pressed. --- extension/src/extension.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/extension/src/extension.ts b/extension/src/extension.ts index 2d680d1..48375f4 100644 --- a/extension/src/extension.ts +++ b/extension/src/extension.ts @@ -82,7 +82,26 @@ export class Extension { } const selection = editor.selection; - const selectedText = editor.document.getText(selection); + + let selectedText; + if (selection.isEmpty) { + const lineText = editor.document.lineAt(selection.start) + .text; + const regexp = /`(.*)`/g; + selectedText = ""; + let match; + while ((match = regexp.exec(lineText))) { + if ( + match.index <= selection.start.character && + selection.start.character <= + match.index + match[0].length + ) { + selectedText = match[1]; + } + } + } else { + selectedText = editor.document.getText(selection); + } if (!selectedText) { return;