feat/preview #3

Merged
Fabel merged 25 commits from feat/preview into develop 2024-10-09 12:27:58 +00:00
1 changed files with 17 additions and 14 deletions
Showing only changes of commit 27571fcad8 - Show all commits

View File

@ -112,31 +112,27 @@ async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationTo
// Split the completion text by new lines // Split the completion text by new lines
const lines = completionText.split('\n'); const lines = completionText.split('\n');
// Define the preview start and end lines // Define the preview start line
const startLine = Math.max(0, position.line); // Use cursor position directly const startLine = position.line;
const endLine = position.line + lines.length;
const rangeToReplace = new vscode.Range( // Apply the preview line by line
new vscode.Position(startLine, 0),
new vscode.Position(endLine, 0)
);
// Apply the preview with multi-line support
const previewRanges = lines.map((line: string, index: number) => { 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 { return {
range: new vscode.Range(linePos, linePos), range: range, // Range for the line
renderOptions: { renderOptions: {
before: { after: {
contentText: line, contentText: line,
color: '#888888', // Grayed-out text 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; let previewInserted = true;
@ -159,6 +155,13 @@ async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationTo
// Replace the context with the actual completion // Replace the context with the actual completion
const acceptedText = completionText; 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); edit.replace(document.uri, rangeToReplace, acceptedText);
await vscode.workspace.applyEdit(edit); await vscode.workspace.applyEdit(edit);