Skip to main content

TextFileView

Extends EditableFileView

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.

Constructor#

constructor(leaf: WorkspaceLeaf);

Properties#

data#

data: string

In memory data

requestSave#

requestSave: () => void

Debounced save in 2 seconds from now

Methods#

onUnloadFile#

onUnloadFile(file: TFile): Promise<void>;

onLoadFile#

onLoadFile(file: TFile): Promise<void>;

save#

save(clear?: boolean): Promise<void>;

getViewData#

abstract getViewData(): string;

Gets the data from the editor. This will be called to save the editor contents to the file.

setViewData#

abstract setViewData(data: string, clear: boolean): 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 clear(), or implement a slightly more efficient clearing mechanism given the new data to be set.

clear#

abstract 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.