Stack Overflow Asked by Chris Lincoln on November 29, 2021
How do you append text past then last line of a document in the editor using an extension?
I have an extension that either creates a new, untitled document, or it appends text to the bottom/end only of an existing document. It is the latter case that I am having trouble with. The extension does not depend on caret/cursor/selection position. I’ve tried both edit.insert() and edit.replace(), with various position/range values of getting past the last character, but my text addition is always placed above the last line:
Before operation (line 20 is the last line of the document):
What I get. Note the existing blank line is below the inserted text:
What I want. Note the existing blank line is above the inserted text.:
The code:
var lastLine = editor.document.lineAt(editor.document.lineCount - 1);
const replaceContent = 'Inserted Text';
editor.edit((editBuilder) => {
editBuilder.replace(lastLine.range.end, replaceContent);
});
I’ve found lots of SO articles for inserting/replacing text, just nothing specific to adding to the very end of an editor buffer.
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP