/** * @file * * Mock of Obsidian's `MarkdownEditView`, the source/live-preview editing mode of a Markdown view. */ import type { HoverPopover as HoverPopoverOriginal, MarkdownEditView as MarkdownEditViewOriginal } from 'obsidian'; import type { App } from './App.mjs'; import type { MarkdownView } from './MarkdownView.mjs'; import type { TFile } from './TFile.mjs'; import { Editor } from './Editor.mjs'; /** * Mock of Obsidian's `MarkdownEditView`. * * The text lives in the view's editor, {@link MarkdownEditView.editor}; the scroll position is only remembered. * A `MarkdownView` registers one of these as its source mode, so its `editor`, `getViewData()` and `data` all * read this one buffer. */ export declare class MarkdownEditView { /** * The app the edit view belongs to, taken from its Markdown view. */ app: App; /** * The in-memory editor holding the edit view's text; the editor its Markdown view exposes as `editor`. */ editor: Editor; /** * The hover popover currently shown for this view, or `null` when there is none. */ hoverPopover: HoverPopoverOriginal | null; /** * The mode this view is, as `MarkdownView.registerMode` keys it and `MarkdownView.getMode()` reports it. */ readonly type = "source"; /** * The file open in the owning Markdown view. * * @returns The Markdown view's file; the mock throws when that view has no file. */ get file(): TFile; private isEditorInitialized; private scroll; private readonly view; /** * Creates the edit mode of a Markdown view. * * @param view - The Markdown view that owns this mode. */ constructor(view: MarkdownView); /** * Mock-only factory: creates an edit view, spyable via `vi.spyOn(MarkdownEditView, 'create__')`. * * @param view - The Markdown view that owns this mode. * @returns The new edit view. */ static create__(view: MarkdownView): MarkdownEditView; /** * Mock-only: views a value typed as Obsidian's `MarkdownEditView` as this mock. * * @param value - The value typed as the original `MarkdownEditView`. * @returns The same object, typed as the mock. */ static fromOriginalType__(value: MarkdownEditViewOriginal): MarkdownEditView; /** * Scrolls the view to a position. The mock only remembers it for {@link MarkdownEditView.getScroll}. * * @param scroll - The scroll position. */ applyScroll(scroll: number): void; /** * Mock-only: views this mock as Obsidian's `MarkdownEditView` type. * * @returns The same object, typed as the original `MarkdownEditView`. */ asOriginalType__(): MarkdownEditViewOriginal; /** * Clears the editor's text into a fresh editor state, as Obsidian does: the undo and redo history is dropped and * the cursor moves to the start. */ clear(): void; /** * Mock-only construction hook, called at the end of the constructor; a no-op meant for * `vi.spyOn(MarkdownEditView.prototype, 'constructor__')`. * * @param _view - The Markdown view the edit view was created with. */ constructor__(_view: MarkdownView): void; /** * Gets the editor's text. * * @returns The current text. */ get(): string; /** * Gets the current scroll position. * * @returns The position last passed to {@link MarkdownEditView.applyScroll}, or `0`. */ getScroll(): number; /** * Gets the text currently selected in the editor. * * @returns The selected text. */ getSelection(): string; /** * Replaces the editor's text. * * @param data - The new text. * @param clear - Whether to reset editor state, as when a different file is loaded: the undo and redo history is * dropped and the cursor moves to the start. An edit view that has never been given a state of its own resets * either way, as Obsidian's does. Otherwise only the lines that differ are changed, as one change that undo can * revert and that the selection is mapped through; identical text is no change at all. */ set(data: string, clear: boolean): void; }