From 27571fcad8e60708fbbe453fcb7c7588d3fa9dd8 Mon Sep 17 00:00:00 2001 From: Falko Habel Date: Mon, 23 Sep 2024 13:25:12 +0200 Subject: [PATCH] still only single line --- src/extension.ts | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 0d06f9c..7088f95 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -112,31 +112,27 @@ async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationTo // Split the completion text by new lines const lines = completionText.split('\n'); - // Define the preview start and end lines - const startLine = Math.max(0, position.line); // Use cursor position directly - const endLine = position.line + lines.length; + // Define the preview start line + const startLine = position.line; - const rangeToReplace = new vscode.Range( - new vscode.Position(startLine, 0), - new vscode.Position(endLine, 0) - ); - - // Apply the preview with multi-line support + // Apply the preview line by line const previewRanges = lines.map((line: string, index: number) => { - const linePos = new vscode.Position(startLine + index, 0); + const linePos = new vscode.Position(startLine + index, 0); // Position each line on a new line + const range = new vscode.Range(linePos, linePos); // Create range for the line + return { - range: new vscode.Range(linePos, linePos), + range: range, // Range for the line renderOptions: { - before: { + after: { contentText: line, color: '#888888', // Grayed-out text - fontStyle: 'italic', // Italic text + fontStyle: 'italic', // Italic text for preview } } }; }); - textEditor.setDecorations(previewDecorationType, previewRanges); + textEditor.setDecorations(previewDecorationType, previewRanges); // Apply the decorations for the preview let previewInserted = true; @@ -159,6 +155,13 @@ async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationTo // Replace the context with the actual completion const acceptedText = completionText; + const endLine = startLine + lines.length; + + const rangeToReplace = new vscode.Range( + new vscode.Position(startLine, 0), + new vscode.Position(endLine, 0) + ); + edit.replace(document.uri, rangeToReplace, acceptedText); await vscode.workspace.applyEdit(edit);