preview extra lines
This commit is contained in:
parent
ffd22f7cc6
commit
6a953b7a12
|
@ -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,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);
|
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()) {
|
||||||
const change = event.contentChanges[0];
|
const change = event.contentChanges[0];
|
||||||
|
|
Loading…
Reference in New Issue