Skip to content

Doc

Unofficial

A CodeMirror 5 document instance.

Import:

import type { Doc } from '@obsidian-typings/obsidian-public-latest';

Signature:

export interface Doc

Properties

Property Type Description
modeOption Cm5ModeSpec<unknown> | string The mode specification for this document.

Methods

Method Returns Description
addLineWidget(line, node, options?) Cm5LineWidget Adds a line widget below the given line.
addSelection(anchor, head?) void Adds a new selection to the existing set of selections.
changeGeneration(closeEvent?) number Returns a number that can later be passed to isClean to test whether any edits were made.
clearHistory() void Clears the editor's undo history.
copy(copyHistory) Doc Create an identical copy of this document.
eachLine(f) void Iterate over the whole document, calling f for each line.
eachLine(start, end, f) void Iterate over a range of lines.
extendSelection(from, to?, options?) void Moves the head of the selection while leaving the anchor in place.
extendSelections(heads, options?) void Like extendSelection, but acts on all selections at once.
extendSelectionsBy(f) void Applies a function to all selections and calls extendSelections on the result.
findMarks(from, to) TextMarker[] Returns an array of all the bookmarks and marked ranges found between the given positions.
findMarksAt(pos) TextMarker[] Returns an array of all the bookmarks and marked ranges at the given position.
firstLine() number Get the first line of the editor.
getAllMarks() TextMarker[] Returns an array containing all marked ranges in the document.
getCursor(start?) Position Gets the cursor position.
getEditor() Cm5Editor | null Retrieve the editor associated with this document.
getExtending() boolean Get the value of the 'extending' flag.
getHistory() unknown Get a JSON-serializable representation of the undo history.
getLine(n) string Gets the content of the given line.
getLineHandle(num) Cm5LineHandle Fetches the line handle for the given line number.
getLineNumber(handle) null | number Given a line handle, returns the current position of that line.
getMode() Cm5Mode<unknown> Gets the mode object for this document.
getRange(from, to, separator?) string Gets the text between the given points.
getSelection(lineSep?) string Gets the currently selected text.
getSelections(lineSep?) string[] Returns an array containing a string for each selection.
getValue(separator?) string Gets the editor content.
historySize() DocHistorySize Gets the number of undo/redo operations available.
indexFromPos(object) number The reverse of posFromIndex.
isClean(generation?) boolean Returns whether the document is currently clean.
iterLinkedDocs(fn) void Will call the given function for all documents linked to this document.
lastLine() number Get the last line of the editor.
lineCount() number Gets the number of lines in the document.
lineSeparator() string Returns the preferred line separator string for this document.
linkedDoc(options) Doc Create a new document linked to this one.
markClean() void Set the editor content as 'clean'.
markText(from, to, options?) TextMarker Marks a range of text with a specific CSS class.
off(eventName, handler) void Removes an event listener.
on(eventName, handler) void Registers an event listener.
posFromIndex(index) Position Calculates a position for a zero-based index.
redo() void Redoes the last undone edit.
redoSelection() void Redo one undone selection change.
removeLine(n) void Remove the given line from the document.
removeLineWidget(widget) void Removes a line widget.
replaceRange(replacement, from, to?, origin?) void Replaces the range between the given points with the given string.
replaceSelection(replacement, select?) void Replaces the current selection with the given string.
replaceSelections(replacements, collapse?, origin?) void Replaces the content of the selections.
setBookmark(pos, options?) TextMarker Inserts a bookmark at the given position.
setCursor(pos, ch?, options?) void Sets the cursor position.
setExtending(value) void Sets or clears the 'extending' flag.
setHistory(history) void Replace the editor's undo history.
setLine(n, text) void Set the content of a given line.
setSelection(anchor, head?, options?) void Sets the selection range.
setSelections(ranges, primary?, options?) void Sets a new set of selections.
setValue(content) void Sets the editor content.
somethingSelected() boolean Tells whether the editor currently has a selection.
undo() void Undoes the last edit.
undoSelection() void Undo one selection change.
unlinkDoc(doc) void Break the link between two documents.

Links to this page: