Fixed unwantted selecting behavior for send-to-chat
The original behavior selects the entire first line even though it's only partially selected in the editor. This fix is to get rid of the extra selection from the first line and only send the exact part that gets selected in the editor to the chat section. However, there is an exception that if the context before the start of the selection contains only whitespace, we want to include the wihitespace into the selection because it's the indentation. https://github.com/Granite-Code/granite-code/issues/43
This commit is contained in:
parent
71eb67d2ab
commit
67957e2225
1 changed files with 14 additions and 3 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue