Skip to content

Commit 7aaebf0

Browse files
committed
Selects expression enclosed in backticks when nothing is selected and shift+F1 is pressed.
1 parent 2f44c2d commit 7aaebf0

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

extension/src/extension.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,26 @@ export class Extension {
8282
}
8383

8484
const selection = editor.selection;
85-
const selectedText = editor.document.getText(selection);
85+
86+
let selectedText;
87+
if (selection.isEmpty) {
88+
const lineText = editor.document.lineAt(selection.start)
89+
.text;
90+
const regexp = /`(.*)`/g;
91+
selectedText = "";
92+
let match;
93+
while ((match = regexp.exec(lineText))) {
94+
if (
95+
match.index <= selection.start.character &&
96+
selection.start.character <=
97+
match.index + match[0].length
98+
) {
99+
selectedText = match[1];
100+
}
101+
}
102+
} else {
103+
selectedText = editor.document.getText(selection);
104+
}
86105

87106
if (!selectedText) {
88107
return;

0 commit comments

Comments
 (0)