I'm building an extension for VsCode
that adds in some text to the line after the editor.active.selection
but I can't figure out how to get the indentation to match that of the previous line and insert the text to the new line.
I have now tried the following (code below) but the second builder.insert
function never seems to target the correct line, it's as if it doesn't know the first builder.insert
has created a new line already.
const endOfSelectedLine = editor.document.lineAt(activeSelection.line).range.end;
const indentValue = editor.document.lineAt(activeSelection.line).firstNonWhitespaceCharacterIndex;
const insertPosition = activeSelection.with(activeSelection.line + 1, indentValue);
editor.edit(builder => {
builder.insert(endOfSelectedLine, '\n');
builder.insert(insertPosition, 'hello');
});