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
|
// Calculate the number of new lines in the completion, plus 2 extra lines
|
||||||
const totalNewLines = newLines.length + 2;
|
const totalNewLines = newLines.length + 2;
|
||||||
|
|
||||||
// Create preview decorations
|
// Create preview decorations and insert new lines
|
||||||
const previewRanges: vscode.DecorationOptions[] = [];
|
const previewRanges: vscode.DecorationOptions[] = [];
|
||||||
|
const edit = new vscode.WorkspaceEdit();
|
||||||
|
const document = textEditor.document;
|
||||||
|
|
||||||
for (let i = 0; i < totalNewLines; i++) {
|
for (let i = 0; i < totalNewLines; i++) {
|
||||||
const lineContent = i < newLines.length ? newLines[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({
|
previewRanges.push({
|
||||||
range,
|
range,
|
||||||
renderOptions: {
|
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);
|
textEditor.setDecorations(previewDecorationType, previewRanges);
|
||||||
|
|
||||||
let previewInserted = true;
|
let previewInserted = true;
|
||||||
|
|
||||||
// Handle preview acceptance or dismissal
|
|
||||||
// Handle preview acceptance or dismissal
|
// Handle preview acceptance or dismissal
|
||||||
const disposable = vscode.workspace.onDidChangeTextDocument(async (event) => {
|
const disposable = vscode.workspace.onDidChangeTextDocument(async (event) => {
|
||||||
if (event.document.uri.toString() === document.uri.toString()) {
|
if (event.document.uri.toString() === document.uri.toString()) {
|
||||||
|
|
Loading…
Reference in New Issue