feat/preview #3
|
@ -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,12 +144,15 @@ 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()) {
|
||||
const change = event.contentChanges[0];
|
||||
|
|
Loading…
Reference in New Issue