still only single line

This commit is contained in:
Falko Victor Habel 2024-09-23 13:25:12 +02:00
parent 66c88a053b
commit 27571fcad8
1 changed files with 17 additions and 14 deletions

View File

@ -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);