-
Notifications
You must be signed in to change notification settings - Fork 77
TextEditor
Jan Richter edited this page Aug 6, 2019
·
10 revisions
import { TextEditor, EditorView } from 'vscode-extension-tester';
...
// to look up current editor
const editor = new TextEditor();
// to look up an open editor by name
const editor1 = await new EditorView().openEditor('package.json');
Note: Most text retrieval and editing actions will make use of the clipboard.
// get all text
const text = await editor.getText();
// get text at a given line number
const line = await editor.getTextAtLine(1);
// get number of lines in the document
const numberOfLines = await editor.getNumberOfLines();
// replace all text with a string
await editor.setText('my fabulous text');
// replace text at a given line number
await editor.setTextAtLine(1, 'my fabulous line');
// type text starting at given coordinates (line, column)
await editor.typeText(1, 3, ' absolutely');
// format the whole document with built-in tools
await editor.formatDocument();
// find if the editor has changes
const hasChanges = await editor.isDirty();
// save the document
await editor.save();
const path = await editor.getFilePath();
// open content assist at current position
const contentAssist = await editor.toggleContentAssist(true);
// close content assist
await editor.toggleContentAssist(false);