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

Property Type Description
cm EditorView CodeMirror editor instance.
containerEl HTMLElement HTML instance the CM editor is attached to.
editorComponent MarkdownScrollableEditView | undefined Linked obsidian#Editor manager instance.

Methods

Method Returns Description
addHighlights(ranges, style, removePrevious, range?) void Make ranges of text highlighted within the editor given specified class (style).
afterIndent() void Clean-up function executed after indenting lists.
blur() void Blur the editor.
coordsAtPos(pos, relativeToEditor) Coords Convert editor position to screen position.
exec(command) void Execute a command.
expandText() void Expand text.
focus() void Focus the editor.
foldLess() void Unfolds all folded lines one level up.
foldMore() void Folds 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 | null Get a clickable link - if it exists - at specified position.
getCursor(string?) EditorPosition Get the cursor position.
getDoc() this Get the editor instance.
getFoldOffsets() Set<number> Get all blocks that were folded by their starting character position.
getLine(line) string Get the text at line index (0-based).
getRange(from, to) string Get the range between two positions.
getScrollInfo() CoordsLeftTop Get the scroll info (horizontal and vertical scroll positions).
getSelection() string Get the selection.
getValue() string Get the content of the editor.
hasFocus() boolean Check if the editor is focused.
hasHighlight(style?) boolean Checks whether the editor has a highlight of specified class.
indentList() void Indents a list by one level.
insertBlock(start, end) void Wraps current line around specified characters.
insertCallout() void Insert a template callout at the current cursor position.
insertCodeblock() void Insert a template code block at the current cursor position.
insertLink() void Insert a markdown link at the current cursor position.
insertMathBlock() void Insert a math block ($$ … $$) at the current cursor position.
insertMathJax() void Insert a mathjax equation block at the current cursor position.
insertText(text) void Insert specified text at the current cursor position.
lastLine() number Get the index of the last line (0-indexed).
lineCount() number Gets the amount of lines in the document.
listSelections() EditorSelection[] Get the list of selections if multiple cursors are active.
newlineAndIndentContinueMarkdownList() void Inserts a new line and continues a markdown bullet point list at the same level.
newlineAndIndentOnly() void Inserts a new line at the same indent level.
newlineOnly() void Inserts a single newline, replacing the current selection.
offsetToPos(offset) EditorPosition Convert an offset to a position.
posAtCoords(x, y) EditorPosition Get the closest character position to the specified coordinates.
posAtMouse(evt) EditorPosition Get the character position at a mouse event.
posToOffset(pos) number Convert a position to an offset.
processLines(read, write, ignoreEmpty?) void Process lines.
redo() void Redo the last action.
refresh() void Refresh the editor.
removeHighlights(style) void Removes all highlights of specified class.
replaceRange(replacement, from, to?, origin?) void Replace the range between two positions.
replaceSelection(replacement, origin?) void Replace the current selection with the given text.
scrollIntoView(range, center?) void Scroll into view.
scrollTo(x?, y?) void Scroll to a specific position.
searchCursor(searchString) SearchCursor Adds a search cursor to the editor.
setCursor(pos, ch?) void Set the cursor position.
setHeading(level) void Sets the markdown heading level of the line(s) under the cursor.
setLine(n, text) void Set the text at line index (0-based).
setSelection(anchor, head?) void Set the selection.
setSelections(ranges, main?) void Set the selections.
setValue(content) void Set the content of the editor.
somethingSelected() boolean Check if there is a selection.
toggleBlockquote() void Toggles blockquote syntax on paragraph under cursor.
toggleBulletList() void Toggle bullet point list syntax on paragraph under cursor.
toggleCheckList() void Toggle checkbox syntax on paragraph under cursor.
toggleMarkdownFormatting(syntax) void Applies specified markdown syntax to selected text or word under cursor.
toggleNumberList() void Toggle numbered list syntax on paragraph under cursor.
transaction(tx, origin?) void Apply a transaction to the editor.
triggerWikiLink(embed) void Convert word under cursor into a wikilink.
undo() void Undo the last action.
unindentList() void Unindents a list by one level.
wordAt(pos) EditorRange | null Get the word at a specific position.

Links to this page: