preview extra lines

This commit is contained in:
Falko Victor Habel 2024-10-03 12:03:05 +03:00
parent ffd22f7cc6
commit 6a953b7a12
1 changed files with 16 additions and 3 deletions

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()) {