Although it may be a little late, I thought I'd share this valuable information for anyone else in a similar situation. To input text into an active editor, you can utilize the TextEditorEdit.insert()
method. [documentation]
function enterText(text: string) {
const editor = vscode.window.activeTextEditor;
if (editor) {
editor.edit(editBuilder => {
editBuilder.insert(editor.selection.active, text);
});
}
}
insert()
requires two arguments:
- location: Position - The position where the new text should be inserted.
- value: string - The new text that should be inserted by this operation.
In the example provided, the text is inserted at the current cursor position. However, if you need to add text to the beginning of the file, you can use the following code:
editBuilder.insert(new vscode.Position(0, 0), text);