Skip to content

Editor

Official

A common interface that bridges the gap between CodeMirror 5 and CodeMirror 6.

Import:

import { Editor } from 'obsidian';

Signature:

export class Editor

Constructor

new Editor()

Constructor.

To extract the constructor type, use ExtractConstructor<Editor>.

Properties

PropertyTypeDescription
cmEditorViewCodeMirror editor instance.
containerElHTMLElementHTML instance the CM editor is attached to.
editorComponentMarkdownScrollableEditView | undefinedLinked obsidian#Editor manager instance.

Methods

MethodReturnsDescription
addHighlights(ranges, style, removePrevious, range?)voidMake ranges of text highlighted within the editor given specified class (style).
afterIndent()voidClean-up function executed after indenting lists.
blur()voidBlur the editor.
coordsAtPos(pos, relativeToEditor)CoordsConvert editor position to screen position.
exec(command)voidExecute a command.
expandText()voidExpand text.
focus()voidFocus the editor.
foldLess()voidUnfolds all folded lines one level up.
foldMore()voidFolds all the blocks that are of the lowest unfolded level.
getAllFoldableLines()Fold[]Get all ranges that can be folded away in the editor.
getClickableTokenAt(pos)ClickableToken | nullGet a clickable link - if it exists - at specified position.
getCursor(string?)EditorPositionGet the cursor position.
getDoc()thisGet the editor instance.
getFoldOffsets()Set<number>Get all blocks that were folded by their starting character position.
getLine(line)stringGet the text at line index (0-based).
getRange(from, to)stringGet the range between two positions.
getScrollInfo()CoordsLeftTopGet the scroll info (horizontal and vertical scroll positions).
getSelection()stringGet the selection.
getValue()stringGet the content of the editor.
hasFocus()booleanCheck if the editor is focused.
hasHighlight(style?)booleanChecks whether the editor has a highlight of specified class.
indentList()voidIndents a list by one level.
insertBlock(start, end)voidWraps current line around specified characters.
insertCallout()voidInsert a template callout at the current cursor position.
insertCodeblock()voidInsert a template code block at the current cursor position.
insertLink()voidInsert a markdown link at the current cursor position.
insertMathBlock()voidInsert a math block ($$ … $$) at the current cursor position.
insertMathJax()voidInsert a mathjax equation block at the current cursor position.
insertText(text)voidInsert specified text at the current cursor position.
lastLine()numberGet the index of the last line (0-indexed).
lineCount()numberGets the amount of lines in the document.
listSelections()EditorSelection[]Get the list of selections if multiple cursors are active.
newlineAndIndentContinueMarkdownList()voidInserts a new line and continues a markdown bullet point list at the same level.
newlineAndIndentOnly()voidInserts a new line at the same indent level.
newlineOnly()voidInserts a single newline, replacing the current selection.
offsetToPos(offset)EditorPositionConvert an offset to a position.
posAtCoords(x, y)EditorPositionGet the closest character position to the specified coordinates.
posAtMouse(evt)EditorPositionGet the character position at a mouse event.
posToOffset(pos)numberConvert a position to an offset.
processLines(read, write, ignoreEmpty?)voidProcess lines.
redo()voidRedo the last action.
refresh()voidRefresh the editor.
removeHighlights(style)voidRemoves all highlights of specified class.
replaceRange(replacement, from, to?, origin?)voidReplace the range between two positions.
replaceSelection(replacement, origin?)voidReplace the current selection with the given text.
scrollIntoView(range, center?)voidScroll into view.
scrollTo(x?, y?)voidScroll to a specific position.
searchCursor(searchString)SearchCursorAdds a search cursor to the editor.
setCursor(pos, ch?)voidSet the cursor position.
setHeading(level)voidSets the markdown heading level of the line(s) under the cursor.
setLine(n, text)voidSet the text at line index (0-based).
setSelection(anchor, head?)voidSet the selection.
setSelections(ranges, main?)voidSet the selections.
setValue(content)voidSet the content of the editor.
somethingSelected()booleanCheck if there is a selection.
toggleBlockquote()voidToggles blockquote syntax on paragraph under cursor.
toggleBulletList()voidToggle bullet point list syntax on paragraph under cursor.
toggleCheckList()voidToggle checkbox syntax on paragraph under cursor.
toggleMarkdownFormatting(syntax)voidApplies specified markdown syntax to selected text or word under cursor.
toggleNumberList()voidToggle numbered list syntax on paragraph under cursor.
transaction(tx, origin?)voidApply a transaction to the editor.
triggerWikiLink(embed)voidConvert word under cursor into a wikilink.
undo()voidUndo the last action.
unindentList()voidUnindents a list by one level.
wordAt(pos)EditorRange | nullGet the word at a specific position.

Links to this page: