Compare commits
No commits in common. "77e0dbc04898ef5b952bd3e65ac6ed1f21182cba" and "0450a222e23b91adb6debd9d5d5f572d3881491b" have entirely different histories.
77e0dbc048
...
0450a222e2
|
@ -113,13 +113,8 @@ async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationTo
|
|||
|
||||
// Create a decoration for each line of the response
|
||||
const previewRanges = lines.map((line: string, idx: number) => {
|
||||
// Determine the start and end positions for each line
|
||||
const startPos = new vscode.Position(position.line + idx, 0);
|
||||
const endPos = new vscode.Position(position.line + idx, line.length);
|
||||
|
||||
// Create a range covering the whole line
|
||||
const range = new vscode.Range(startPos, endPos);
|
||||
|
||||
const linePos = new vscode.Position(position.line + idx, 0);
|
||||
const range = new vscode.Range(linePos, linePos); // Set range at the start of each new line
|
||||
return {
|
||||
range,
|
||||
renderOptions: {
|
||||
|
@ -135,8 +130,6 @@ async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationTo
|
|||
// Apply the decorations for multiline preview
|
||||
textEditor.setDecorations(previewDecorationType, previewRanges);
|
||||
|
||||
let completionInserted = false; // Flag to track insertion
|
||||
|
||||
const disposable = vscode.workspace.onDidChangeTextDocument(async (event) => {
|
||||
if (event.document.uri.toString() === document.uri.toString()) {
|
||||
const change = event.contentChanges[0];
|
||||
|
@ -156,17 +149,14 @@ async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationTo
|
|||
}
|
||||
);
|
||||
|
||||
if (isCtrlOrCmdPressed && !completionInserted) {
|
||||
// Ensure that we insert the completion text only once
|
||||
completionInserted = true;
|
||||
|
||||
if (isCtrlOrCmdPressed) {
|
||||
// Remove the preview decoration before applying the final completion
|
||||
textEditor.setDecorations(previewDecorationType, []);
|
||||
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
const insertPosition = new vscode.Position(position.line, 0);
|
||||
|
||||
// Avoid duplicating the completion text
|
||||
// Insert the completion only once
|
||||
if (!document.getText().includes(completionText)) {
|
||||
edit.insert(document.uri, insertPosition, '\n' + completionText);
|
||||
await vscode.workspace.applyEdit(edit);
|
||||
|
@ -188,8 +178,6 @@ async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationTo
|
|||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue