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 16 additions and 3 deletions
Showing only changes of commit 6a953b7a12 - Show all commits

View File

@ -119,11 +119,21 @@ async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationTo
// Calculate the number of new lines in the completion, plus 2 extra lines
const totalNewLines = newLines.length + 2;
// Create preview decorations
// Create preview decorations and insert new lines
const previewRanges: vscode.DecorationOptions[] = [];
const edit = new vscode.WorkspaceEdit();
const document = textEditor.document;
for (let i = 0; i < totalNewLines; i++) {
const lineContent = i < newLines.length ? newLines[i] : '';
const range = new vscode.Range(startLine + i, 0, startLine + i + 1, 0);
const position = new vscode.Position(startLine + i, 0);
// Insert a new line
edit.insert(document.uri, position, '\n');
// Create a range for the newly inserted line
const range = new vscode.Range(position, position.translate(1, 0));
previewRanges.push({
range,
renderOptions: {
@ -134,11 +144,14 @@ async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationTo
});
}
// Apply the edit to insert new lines
await vscode.workspace.applyEdit(edit);
// Set decorations on the newly inserted lines
textEditor.setDecorations(previewDecorationType, previewRanges);
let previewInserted = true;
// Handle preview acceptance or dismissal
// Handle preview acceptance or dismissal
const disposable = vscode.workspace.onDidChangeTextDocument(async (event) => {
if (event.document.uri.toString() === document.uri.toString()) {