Skip to content

Commit 8cf5004

Browse files
committed
feat: allow Cmd+L / Cmd+I on empty selection to select the entire line
Signed-off-by: Fred Bricon <[email protected]>
1 parent 902e59f commit 8cf5004

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

extensions/vscode/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,13 +525,12 @@
525525
"continue.continueSubMenu": [
526526
{
527527
"command": "continue.focusContinueInputWithoutClear",
528-
"group": "Continue",
529-
"when": "editorHasSelection"
528+
"group": "Continue"
530529
},
531530
{
532531
"command": "continue.focusEdit",
533532
"group": "Continue",
534-
"when": "editorHasSelection && !editorReadonly"
533+
"when": "!editorReadonly"
535534
},
536535
{
537536
"command": "continue.writeCommentsForCode",

extensions/vscode/src/util/addCode.ts

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,34 @@ export function getRangeInFileWithContents(
4040
return null;
4141
}
4242

43-
let selectionRange = new vscode.Range(selection.start, selection.end);
44-
const document = editor.document;
45-
// Select the context from the beginning of the selection start line to the selection start position
46-
const beginningOfSelectionStartLine = selection.start.with(undefined, 0);
47-
const textBeforeSelectionStart = document.getText(
48-
new vscode.Range(beginningOfSelectionStartLine, selection.start),
49-
);
50-
// If there are only whitespace before the start of the selection, include the indentation
51-
if (textBeforeSelectionStart.trim().length === 0) {
52-
selectionRange = selectionRange.with({
53-
start: beginningOfSelectionStartLine,
54-
});
43+
let selectionRange: vscode.Range | undefined;
44+
// if the selection is empty and the line is not, then use the entire line
45+
if (selection.isEmpty) {
46+
const startLine = editor.document.lineAt(selection.start.line);
47+
if (startLine.isEmptyOrWhitespace) {
48+
// Empty selection on an empty line, nothing else to do here
49+
return null;
50+
}
51+
// Select the whole line
52+
selectionRange = new vscode.Range(
53+
selection.start.with(undefined, 0),
54+
selection.end.with(undefined, startLine.range.end.character),
55+
);
56+
}
57+
if (!selectionRange) {
58+
selectionRange = new vscode.Range(selection.start, selection.end);
59+
const document = editor.document;
60+
// Select the context from the beginning of the selection start line to the selection start position
61+
const beginningOfSelectionStartLine = selection.start.with(undefined, 0);
62+
const textBeforeSelectionStart = document.getText(
63+
new vscode.Range(beginningOfSelectionStartLine, selection.start),
64+
);
65+
// If there are only whitespace before the start of the selection, include the indentation
66+
if (textBeforeSelectionStart.trim().length === 0) {
67+
selectionRange = selectionRange.with({
68+
start: beginningOfSelectionStartLine,
69+
});
70+
}
5571
}
5672

5773
const contents = editor.document.getText(selectionRange);
@@ -78,7 +94,7 @@ export function getRangeInFileWithContents(
7894
export async function addHighlightedCodeToContext(
7995
webviewProtocol: VsCodeWebviewProtocol | undefined,
8096
) {
81-
const rangeInFileWithContents = getRangeInFileWithContents();
97+
const rangeInFileWithContents = getRangeInFileWithContents(true);
8298
if (rangeInFileWithContents) {
8399
webviewProtocol?.request("highlightedCode", {
84100
rangeInFileWithContents,

0 commit comments

Comments
 (0)