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

PropertyTypeDescription
modeOptionCm5ModeSpec<unknown> | stringThe mode specification for this document.

Methods

MethodReturnsDescription
addLineWidget(line, node, options?)Cm5LineWidgetAdds a line widget below the given line.
addSelection(anchor, head?)voidAdds a new selection to the existing set of selections.
changeGeneration(closeEvent?)numberReturns a number that can later be passed to isClean to test whether any edits were made.
clearHistory()voidClears the editor's undo history.
copy(copyHistory)DocCreate an identical copy of this document.
eachLine(f)voidIterate over the whole document, calling f for each line.
eachLine(start, end, f)voidIterate over a range of lines.
extendSelection(from, to?, options?)voidMoves the head of the selection while leaving the anchor in place.
extendSelections(heads, options?)voidLike extendSelection, but acts on all selections at once.
extendSelectionsBy(f)voidApplies 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()numberGet the first line of the editor.
getAllMarks()TextMarker[]Returns an array containing all marked ranges in the document.
getCursor(start?)PositionGets the cursor position.
getEditor()Cm5Editor | nullRetrieve the editor associated with this document.
getExtending()booleanGet the value of the 'extending' flag.
getHistory()unknownGet a JSON-serializable representation of the undo history.
getLine(n)stringGets the content of the given line.
getLineHandle(num)Cm5LineHandleFetches the line handle for the given line number.
getLineNumber(handle)null | numberGiven a line handle, returns the current position of that line.
getMode()Cm5Mode<unknown>Gets the mode object for this document.
getRange(from, to, separator?)stringGets the text between the given points.
getSelection(lineSep?)stringGets the currently selected text.
getSelections(lineSep?)string[]Returns an array containing a string for each selection.
getValue(separator?)stringGets the editor content.
historySize()DocHistorySizeGets the number of undo/redo operations available.
indexFromPos(object)numberThe reverse of posFromIndex.
isClean(generation?)booleanReturns whether the document is currently clean.
iterLinkedDocs(fn)voidWill call the given function for all documents linked to this document.
lastLine()numberGet the last line of the editor.
lineCount()numberGets the number of lines in the document.
lineSeparator()stringReturns the preferred line separator string for this document.
linkedDoc(options)DocCreate a new document linked to this one.
markClean()voidSet the editor content as 'clean'.
markText(from, to, options?)TextMarkerMarks a range of text with a specific CSS class.
off(eventName, handler)voidRemoves an event listener.
on(eventName, handler)voidRegisters an event listener.
posFromIndex(index)PositionCalculates a position for a zero-based index.
redo()voidRedoes the last undone edit.
redoSelection()voidRedo one undone selection change.
removeLine(n)voidRemove the given line from the document.
removeLineWidget(widget)voidRemoves a line widget.
replaceRange(replacement, from, to?, origin?)voidReplaces the range between the given points with the given string.
replaceSelection(replacement, select?)voidReplaces the current selection with the given string.
replaceSelections(replacements, collapse?, origin?)voidReplaces the content of the selections.
setBookmark(pos, options?)TextMarkerInserts a bookmark at the given position.
setCursor(pos, ch?, options?)voidSets the cursor position.
setExtending(value)voidSets or clears the 'extending' flag.
setHistory(history)voidReplace the editor's undo history.
setLine(n, text)voidSet the content of a given line.
setSelection(anchor, head?, options?)voidSets the selection range.
setSelections(ranges, primary?, options?)voidSets a new set of selections.
setValue(content)voidSets the editor content.
somethingSelected()booleanTells whether the editor currently has a selection.
undo()voidUndoes the last edit.
undoSelection()voidUndo one selection change.
unlinkDoc(doc)voidBreak the link between two documents.

Links to this page: