Skip to content

Fixed unwantted selecting behavior for send-to-chat #4515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions extensions/vscode/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,20 @@ function getRangeInFileWithContents(
return null;
}

// adjust starting position to include indentation
const start = new vscode.Position(selection.start.line, 0);
const selectionRange = new vscode.Range(start, selection.end);
let selectionRange = new vscode.Range(selection.start, selection.end);
const document = editor.document;
// Select the context from the beginning of the selection start line to the selection start position
const beginningOfSelectionStartLine = selection.start.with(undefined, 0);
const textBeforeSelectionStart = document.getText(
new vscode.Range(beginningOfSelectionStartLine, selection.start),
);
// If there are only whitespace before the start of the selection, include the indentation
if (textBeforeSelectionStart.trim().length === 0) {
selectionRange = selectionRange.with({
start: beginningOfSelectionStartLine,
});
}

const contents = editor.document.getText(selectionRange);

return {
Expand Down
Loading