From fb6e9a5d1f97a06dabbf1a1c3dd637c00d25a46b Mon Sep 17 00:00:00 2001 From: Falko Habel Date: Wed, 11 Sep 2024 09:58:26 +0200 Subject: [PATCH] new approach --- src/extension.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 15fd0fe..4b30205 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -108,23 +108,23 @@ async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationTo let completionText = response.data.response; completionText = completionText.replace(/||/g, '').trim(); + // Split the completion text by new lines // Split the completion text by new lines const lines = completionText.split('\n'); // 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 + // Determine the start position 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); + + // Create a range that decorates the line, spanning from start to start (empty range) + const range = new vscode.Range(startPos, startPos); return { range, renderOptions: { - before: { - contentText: line, + after: { + contentText: line, // Display the current line color: '#888888', fontStyle: 'italic', } @@ -134,6 +134,7 @@ async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationTo // Apply the decorations for multiline preview textEditor.setDecorations(previewDecorationType, previewRanges); + let completionInserted = false; // Flag to track insertion