I’m writing a VS Code extension in TypeScript and need to insert indented text in a TextDocument using tabs or spaces as indicated by the TextEditorOptions. I can handle the resolution of tabs manually but I’m wondering if there is an idiomatic way using the VSCode API.
Indent position is taken from TextEditor.selection.end.character
. If tabs are used, this will not be the actual insert location without adjusting for TextEditorOptions.tabSize
.
<code>int main(int argc, const char *argv[]) {
int countdown = -1;
Text to be inserted here.
^^^^^^^^Need to indent with tabs.
static const char invalid[] = "Invalid countdown %s, try again...n";
if (argc > 1) {
char* end;
countdown = strtol(argv[1], &end, 10);
</code>
<code>int main(int argc, const char *argv[]) {
int countdown = -1;
Text to be inserted here.
^^^^^^^^Need to indent with tabs.
static const char invalid[] = "Invalid countdown %s, try again...n";
if (argc > 1) {
char* end;
countdown = strtol(argv[1], &end, 10);
</code>
int main(int argc, const char *argv[]) {
int countdown = -1;
Text to be inserted here.
^^^^^^^^Need to indent with tabs.
static const char invalid[] = "Invalid countdown %s, try again...n";
if (argc > 1) {
char* end;
countdown = strtol(argv[1], &end, 10);
Is there some feature in the API that will handle insertion of tabs/spaces automatically or do I need to do it manually?