develop #6

Merged
Fabel merged 35 commits from develop into main 2024-10-09 18:50:26 +00:00
1 changed files with 25 additions and 18 deletions
Showing only changes of commit 8ac3879ee0 - Show all commits

View File

@ -130,6 +130,8 @@ async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationTo
// Apply the decorations for multiline preview // Apply the decorations for multiline preview
textEditor.setDecorations(previewDecorationType, previewRanges); textEditor.setDecorations(previewDecorationType, previewRanges);
let completionInserted = false; // Flag to track insertion
const disposable = vscode.workspace.onDidChangeTextDocument(async (event) => { const disposable = vscode.workspace.onDidChangeTextDocument(async (event) => {
if (event.document.uri.toString() === document.uri.toString()) { if (event.document.uri.toString() === document.uri.toString()) {
const change = event.contentChanges[0]; const change = event.contentChanges[0];
@ -149,14 +151,17 @@ async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationTo
} }
); );
if (isCtrlOrCmdPressed) { if (isCtrlOrCmdPressed && !completionInserted) {
// Ensure that we insert the completion text only once
completionInserted = true;
// Remove the preview decoration before applying the final completion // Remove the preview decoration before applying the final completion
textEditor.setDecorations(previewDecorationType, []); textEditor.setDecorations(previewDecorationType, []);
const edit = new vscode.WorkspaceEdit(); const edit = new vscode.WorkspaceEdit();
const insertPosition = new vscode.Position(position.line, 0); const insertPosition = new vscode.Position(position.line, 0);
// Insert the completion only once // Avoid duplicating the completion text
if (!document.getText().includes(completionText)) { if (!document.getText().includes(completionText)) {
edit.insert(document.uri, insertPosition, '\n' + completionText); edit.insert(document.uri, insertPosition, '\n' + completionText);
await vscode.workspace.applyEdit(edit); await vscode.workspace.applyEdit(edit);
@ -178,6 +183,8 @@ async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationTo
} }
} }
); );
} }