TextFileView
Official
This class implements a plaintext-based editable file view, which can be loaded and saved given an editor.
Note that by default, this view only saves when it’s closing. To implement auto-save, your editor should call this.requestSave() when the content is changed.
Import:
import { TextFileView } from 'obsidian';Signature:
export class TextFileView extends EditableFileViewExtends: EditableFileView
Constructor
new TextFileView(leaf: WorkspaceLeaf)Constructor.
To extract the constructor type, use ExtractConstructor<EditableFileView>.
Properties
| Property | Type | Description | |
|---|---|---|---|
| allowNoFile | boolean | Whether the view may be run without an attached file.. (Inherited from EditableFileView) | |
| data | string | In-memory data. | |
| dirty | boolean | Whether current file is dirty (different from saved contents). | |
| file | null | TFile | The file that is currently being viewed. (Inherited from EditableFileView) | |
| fileBeingRenamed | null | TFile | The file that is currently being renamed. (Inherited from EditableFileView) | |
| isPlaintext | boolean | Whether editor should be rendered as plaintext. | |
| lastSavedData | null | string | The data that was last saved. | |
| navigation | boolean | Whether the file view can be navigated. (Inherited from EditableFileView) | |
| requestSave | () => void | Debounced save in 2 seconds from now | |
| saveAgain | boolean | Whether on saving, the file should be saved again (for dirtiness checks). | |
| saving | boolean | Whether the file is currently saving. |
Methods
| Method | Returns | Description | |
|---|---|---|---|
| canAcceptExtension(extension) | boolean | Whether the file view can accept an extension. (Inherited from EditableFileView) | |
| clear() | void | Clear the editor. This is usually called when we're about to open a completely different file, so it's best to clear any editor states like undo-redo history, and any caches/indexes associated with the previous file contents. | |
| getDisplayText() | string | Get the display text for the file view. (Inherited from EditableFileView) | |
| getState() | Record<string, unknown> | Get the state of the file view. (Inherited from EditableFileView) | |
| getSyncViewState() | unknown | Get view state for sync plugin. (Inherited from EditableFileView) | |
| getViewData() | string | Gets the data from the editor. This will be called to save the editor contents to the file. | |
| loadFile(file) | Promise<unknown> | Loads the file with the onLoadFile function. (Inherited from EditableFileView) | |
| loadFileInternal(file, clear) | Promise<unknown> | Load a file into the editor, optionally clearing existing content. | |
| onDelete(file) | Promise<void> | Updates the view if it contains the deleted file. (Inherited from EditableFileView) | |
| onload() | void | Called when the file view is loaded. (Inherited from EditableFileView) | |
| onLoadFile(file) | Promise<void> | On load file. | |
| onModify(file) | void | Is called when the vault has a 'modify' event. Reloads the file if the view is currently not saving the file and the modified file is the file in this view. | |
| onRename(file) | Promise<void> | Called when the file is renamed. (Inherited from EditableFileView) | |
| onTitleBlur() | Promise<void> | Is called when the titleEl looses focus. Event type: 'blur'. (Inherited from EditableFileView) | |
| onTitleChange(titleEl) | void | Is called when the titleEl is changed. Event type: 'input'. (Inherited from EditableFileView) | |
| onTitleFocus() | void | Is called when the titleEl gains focus. Event type: 'focus'. (Inherited from EditableFileView) | |
| onTitleKeydown(event) | void | Is called when the titleEl is focused and a keydown is triggered. Event type: 'keydown'. (Inherited from EditableFileView) | |
| onTitlePaste(titleEl, event) | void | Is called when the titleEl is focused and a paste event is triggered. Event type: 'paste'. (Inherited from EditableFileView) | |
| onUnloadFile(file) | Promise<void> | On unload file. | |
| receiveSyncState(view) | void | Receives sync state from another file view, opening the other view's file if it differs. (Inherited from EditableFileView) | |
| renderBreadcrumbs() | void | Render the breadcrumb navigation for this file view. (Inherited from EditableFileView) | |
| save(clear?) | Promise<void> | Save the file. | |
| saveImmediately() | void | If any changes(dirty = true) in the file forces the file to save. | |
| saveTitle(titleEl) | Promise<void> | Updates the file to match the updated title. (Inherited from EditableFileView) | |
| setData(data, clear) | void | Set the data to the editor. This is used to load the file contents. | |
| setState(state, result) | Promise<void> | Set the state of the file view. (Inherited from EditableFileView) | |
| setViewData(data, clear) | void | Set the data to the editor. This is used to load the file contents. If clear is set, then it means we're opening a completely different file. In that case, you should call TextFileView.clear(), or implement a slightly more efficient clearing mechanism given the new data to be set. | |
| syncState(e) | Promise<unknown> | Synchronize the view state with the sync plugin. (Inherited from EditableFileView) |
Links to this page: