/** * @file * * Mock of Obsidian's `TextFileView`, a file view that edits a file's contents as text. */ import type { TextFileView as TextFileViewOriginal } from 'obsidian'; import type { TFile } from './TFile.cjs'; import type { WorkspaceLeaf } from './WorkspaceLeaf.cjs'; import { EditableFileView } from './EditableFileView.cjs'; /** * Mock of Obsidian's `TextFileView` base class. * * Loading, unloading and saving do not touch the vault: they are no-ops, so a test drives * {@link TextFileView.setViewData} and {@link TextFileView.getViewData} directly. */ export declare abstract class TextFileView extends EditableFileView { /** * The file's contents held in memory; empty until a subclass sets it. * * @returns The text last written to it. */ get data(): string; /** * Stores the file's contents in memory. * * @param value - The text to hold. */ set data(value: string); private dataValue; /** * Creates the view in a leaf. * * @param leaf - The workspace leaf that hosts the view. */ constructor(leaf: WorkspaceLeaf); /** * Mock-only: views a value typed as Obsidian's `TextFileView` as this mock. * * @param value - The value typed as the original `TextFileView`. * @returns The same object, typed as the mock. */ static fromOriginalType6__(value: TextFileViewOriginal): TextFileView; /** * Mock-only: views this mock as Obsidian's `TextFileView` type. * * @returns The same object, typed as the original `TextFileView`. */ asOriginalType6__(): TextFileViewOriginal; /** * Clears the editor, including undo history and any caches tied to the previous file's contents; called before a * different file is opened. */ abstract clear(): void; /** * Mock-only construction hook, called at the end of the constructor; a no-op meant for * `vi.spyOn(TextFileView.prototype, 'constructor6__')`. * * @param _leaf - The leaf the view was created in. */ constructor6__(_leaf: WorkspaceLeaf): void; /** * Gets the editor's contents; called to save them to the file. * * @returns The text to write to the file. */ abstract getViewData(): string; /** * Called when a file is loaded into the view; Obsidian reads it and calls `setViewData`. A no-op in the mock. * * @param _file - The file being loaded. */ onLoadFile(_file: TFile): Promise; /** * Called when a file is unloaded from the view; Obsidian saves pending changes first. A no-op in the mock. * * @param _file - The file being unloaded. */ onUnloadFile(_file: TFile): Promise; /** * Requests a debounced save, two seconds from now. A no-op in the mock. */ requestSave(): void; /** * Saves the view's data to its file. A no-op in the mock. * * @param _clear - Whether to clear the view after saving. */ save(_clear?: boolean): Promise; /** * Loads contents into the editor. * * @param data - The file contents. * @param clear - Whether a completely different file is being opened, so the editor state should be cleared. */ abstract setViewData(data: string, clear: boolean): void; }