TextDocument
interfaceRepresents a text document, such as a source file. Text documents have lines and knowledge about an underlying resource like a file.
Import
import { TextDocument } from '@modular/sdk/view';Members18
- encoding
stringThe file encoding of this document that will be used when the document is saved. Use the workspace.onDidChangeTextDocument onDidChangeTextDocument-event to get notified when the document encoding changes. Note that the possible encoding values are currently defined as any of the following: 'utf8', 'utf8bom', 'utf16le', 'utf16be', 'windows1252', 'iso88591', 'iso88593', 'iso885915', 'macroman', 'cp437', 'windows1256', 'iso88596', 'windows1257', 'iso88594', 'iso885914', 'windows1250', 'iso88592', 'cp852', 'windows1251', 'cp866', 'cp1125', 'iso88595', 'koi8r', 'koi8u', 'iso885913', 'windows1253', 'iso88597', 'windows1255', 'iso88598', 'iso885910', 'iso885916', 'windows1254', 'iso88599', 'windows1258', 'gbk', 'gb18030', 'cp950', 'big5hkscs', 'shiftjis', 'eucjp', 'euckr', 'windows874', 'iso885911', 'koi8ru', 'koi8t', 'gb2312', 'cp865', 'cp850', 'cp857'.
- eol
EndOfLineThe end of line sequence that is predominately used in this document.
- fileName
stringThe file system path of the associated resource. Shorthand notation for TextDocument.uri.fsPath. Independent of the uri scheme.
- isClosed
boolean`true` if the document has been closed. A closed document isn't synchronized anymore and won't be re-used when the same resource is opened again.
- isDirty
boolean`true` if there are unpersisted changes.
- isUntitled
booleanIs this document representing an untitled file which has never been saved yet. *Note* that this does not mean the document will be saved to disk, use Uri.scheme to figure out where a document will be saved, e.g. `file`, `ftp` etc.
- languageId
stringThe identifier of the language associated with this document.
- lineCount
numberThe number of lines in this document.
- uri
UriThe associated uri for this document. *Note* that most documents use the `file`-scheme, which means they are files on disk. However, **not** all documents are saved on disk and therefore the `scheme` must be checked before trying to access the underlying file or siblings on disk.
- version
numberThe version number of this document (it will strictly increase after each change, including undo/redo).
- getText()
(range?: Range) => stringGet the text of this document. A substring can be retrieved by providing a range. The range will be adjusted.
- getWordRangeAtPosition()
(position: Position, regex?: RegExp) => Range | undefinedGet a word-range at the given position. By default words are defined by common separators, like space, -, _, etc. In addition, per language custom [word definitions] can be defined. It is also possible to provide a custom regular expression. * *Note 1:* A custom regular expression must not match the empty string and if it does, it will be ignored. * *Note 2:* A custom regular expression will fail to match multiline strings and in the name of speed regular expressions should not match words with spaces. Use TextLine.text for more complex, non-wordy, scenarios. The position will be adjusted.
- lineAt()
(line: number) => TextLine | (position: Position) => TextLineReturns a text line denoted by the line number. Note that the returned object is *not* live and changes to the document are not reflected. Returns a text line denoted by the position. Note that the returned object is *not* live and changes to the document are not reflected. The position will be adjusted.
- offsetAt()
(position: Position) => numberConverts the position to a zero-based offset. The position will be adjusted.
- positionAt()
(offset: number) => PositionConverts a zero-based offset to a position.
- save()
() => Thenable<boolean>Save the underlying file.
- validatePosition()
(position: Position) => PositionEnsure a position is contained in the range of this document.
- validateRange()
(range: Range) => RangeEnsure a range is completely contained in this document.