Skip to content

Commit 3d7b1aa

Browse files
committed
Fix #182: Run Selection doesn't capture whole line
This change fixes an issue with the "Run Selection" command when it is executed on a line without any text being selected. In this case the expected behavior is to execute the entire line but only the line contents up to the cursor position were being executed. The fix is to change the content selection code to ensure that the line's full content is executed.
1 parent cab5543 commit 3d7b1aa

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/features/Console.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,20 @@ export function registerConsoleCommands(client: LanguageClient): void {
142142

143143
vscode.commands.registerCommand('PowerShell.RunSelection', () => {
144144
var editor = vscode.window.activeTextEditor;
145-
var start = editor.selection.start;
146-
var end = editor.selection.end;
147-
if (editor.selection.isEmpty) {
148-
start = new vscode.Position(start.line, 0)
145+
var selectionRange: vscode.Range = undefined;
146+
147+
if (!editor.selection.isEmpty) {
148+
selectionRange =
149+
new vscode.Range(
150+
editor.selection.start,
151+
editor.selection.end);
152+
}
153+
else {
154+
selectionRange = editor.document.lineAt(editor.selection.start.line).range;
149155
}
156+
150157
client.sendRequest(EvaluateRequest.type, {
151-
expression:
152-
editor.document.getText(
153-
new vscode.Range(start, end))
158+
expression: editor.document.getText(selectionRange)
154159
});
155160
});
156161

0 commit comments

Comments
 (0)