diff --git a/src/lfview/lf-data-provider.ts b/src/lfview/lf-data-provider.ts index 1262176d6..9acf9d9fe 100644 --- a/src/lfview/lf-data-provider.ts +++ b/src/lfview/lf-data-provider.ts @@ -212,7 +212,9 @@ export class LFDataProvider implements vscode.TreeDataProvider { + this._onDidChangeTreeData.fire(element); + }) } } @@ -410,16 +412,7 @@ export class LFDataProvider implements vscode.TreeDataProvider { const document = editor.document; - const totalLines = document.lineCount; - - let startIndex = end; - let foundEmptyLine = false; - - while (startIndex < totalLines) { - const line = document.lineAt(startIndex); - if (line.isEmptyOrWhitespace) { - foundEmptyLine = true; - break; - } - startIndex++; - } - - if (foundEmptyLine) { - editor.edit(editBuilder => { - editBuilder.insert(new vscode.Position(startIndex, 0), importText); + try { + const success = await editor.edit(editBuilder => { + editBuilder.insert(new vscode.Position(idx, 0), importText); }); + if (success) { + await document.save(); + } + } catch (error) { + console.error('Failed to add text or save document:', error); } }