TextFileView class
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.
Signature:
export abstract class TextFileView extends EditableFileView
Extends: EditableFileView
Constructors
Constructor | Modifiers | Description |
---|---|---|
(constructor)(leaf) | Constructs a new instance of the TextFileView class |
Properties
Property | Modifiers | Type | Description |
---|---|---|---|
allowNoFile | boolean | (Inherited from FileView) | |
app | App | (Inherited from View) | |
containerEl | HTMLElement | (Inherited from View) | |
contentEl | HTMLElement | (Inherited from ItemView) | |
data | string | In memory data | |
file | TFile | null | (Inherited from FileView) | |
icon | IconName | (Inherited from View) | |
leaf | WorkspaceLeaf | (Inherited from View) | |
navigation | boolean | File views can be navigated by default. (Inherited from FileView) | |
requestSave | () โ void | Debounced save in 2 seconds from now | |
scope | Scope | null | Assign an optional scope to your view to register hotkeys for when the view is in focus. (Inherited from View) |
Methods
Method | Modifiers | Description |
---|---|---|
addAction(icon, title, callback) | (Inherited from ItemView) | |
addChild(component) | Adds a child component, loading it if this component is loaded (Inherited from Component) | |
canAcceptExtension(extension) | (Inherited from FileView) | |
clear() | abstract | 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() | (Inherited from FileView) | |
getEphemeralState() | (Inherited from View) | |
getIcon() | (Inherited from View) | |
getState() | (Inherited from FileView) | |
getViewData() | abstract | Gets the data from the editor. This will be called to save the editor contents to the file. |
getViewType() | abstract | (Inherited from View) |
load() | Load this component and its children (Inherited from Component) | |
onClose() | protected | (Inherited from View) |
onload() | (Inherited from FileView) | |
onLoadFile(file) | ||
onOpen() | protected | (Inherited from View) |
onPaneMenu(menu, source) | Populates the pane menu. (Replaces the previously removed (Inherited from View) | |
onRename(file) | (Inherited from FileView) | |
onResize() | Called when the size of this view is changed. (Inherited from View) | |
onunload() | Override this to unload your component (Inherited from Component) | |
onUnloadFile(file) | ||
register(cb) | Registers a callback to be called when unloading (Inherited from Component) | |
registerDomEvent(el, type, callback, options) | Registers an DOM event to be detached when unloading (Inherited from Component) | |
registerDomEvent(el, type, callback, options) | Registers an DOM event to be detached when unloading (Inherited from Component) | |
registerDomEvent(el, type, callback, options) | Registers an DOM event to be detached when unloading (Inherited from Component) | |
registerEvent(eventRef) | Registers an event to be detached when unloading (Inherited from Component) | |
registerInterval(id) | Registers an interval (from setInterval) to be cancelled when unloading Use instead of to avoid TypeScript confusing between NodeJS vs Browser API (Inherited from Component) | |
removeChild(component) | Removes a child component, unloading it (Inherited from Component) | |
save(clear) | ||
setEphemeralState(state) | (Inherited from View) | |
setState(state, result) | (Inherited from FileView) | |
setViewData(data, clear) | abstract | 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 clear(), or implement a slightly more efficient clearing mechanism given the new data to be set. |
unload() | Unload this component and its children (Inherited from Component) |