Skip to content

obsidian/Editor

Mock of Obsidian’s Editor, backed by an in-memory string buffer.

Class Description
Editor Mock of Obsidian’s abstract Editor, the common interface over the CodeMirror editors. The document is a plain string with \n line breaks. The mock tracks one selection (an anchor and a head), focus and scroll position, and keeps whole-document snapshots for undo and redo, each carrying the selection its change started from. Folding and scrolling a range into view are no-ops. Two properties of CodeMirror’s history are deliberately not modelled, because both would make the mock’s history depend on wall-clock time or on where the cursor has been since a change: a bare selection change is not recorded against the last change (CodeMirror’s selectionsAfter, which would take precedence over the mapped selection when redoing), and consecutive typing or deleting changes are never grouped into one history entry (CodeMirror’s addChanges joins them within its newGroupDelay, keyed on the origin the mock ignores).