Skip to content

Editor

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

Extends

Constructors

new Editor()

new Editor(): Editor

Returns

Editor

Properties

cm

cm: EditorView

CodeMirror editor instance

Inherited from

BaseEditor.cm


containerEl

containerEl: HTMLElement

HTML instance the CM editor is attached to

Inherited from

BaseEditor.containerEl


editorComponent

editorComponent: undefined | MarkdownScrollableEditView

Linked Editor manager instance

Accessors

activeCm

get activeCm(): null | EditorView

Currently active CM instance

Returns

null | EditorView


inTableCell

get inTableCell(): boolean

Whether the editor is embedded in a table cell

Returns

boolean

Methods

addHighlights()

addHighlights(ranges, style, remove_previous, range?): void

Make ranges of text highlighted within the editor given specified class (style)

Parameters

ranges: EditorRange[]

style: "is-flashing" | "obsidian-search-match-highlight"

remove_previous: boolean

range?: EditorSelection

Returns

void


afterIndent()

afterIndent(): void

Clean-up function executed after indenting lists

Returns

void

Inherited from

BaseEditor.afterIndent


blur()

abstract blur(): void

Returns

void


coordsAtPos()

coordsAtPos(pos, relative_to_editor): object

Convert editor position to screen position

Parameters

pos: EditorPosition

Editor position

relative_to_editor: boolean

Relative to the editor or the application window

Returns

object

bottom

bottom: number

left

left: number

right: number

top

top: number


exec()

abstract exec(command): void

Parameters

command: EditorCommandName

Returns

void


focus()

abstract focus(): void

Returns

void


foldLess()

foldLess(): void

Unfolds all folded lines one level up

Returns

void


foldMore()

foldMore(): void

Folds all the blocks that are of the lowest unfolded level

Returns

void


getAllFoldableLines()

getAllFoldableLines(): object[]

Get all ranges that can be folded away in the editor

Returns

object[]


getClickableTokenAt()

getClickableTokenAt(pos): null | object

Get a clickable link - if it exists - at specified position

Parameters

pos: EditorPosition

Returns

null | object


getCursor()

abstract getCursor(string?): EditorPosition

Parameters

string?: "from" | "to" | "head" | "anchor"

Returns

EditorPosition


getDoc()

getDoc(): this

Returns

this


getFoldOffsets()

getFoldOffsets(): Set<number>

Get all blocks that were folded by their starting character position

Returns

Set<number>


getLine()

abstract getLine(line): string

Get the text at line (0-indexed)

Parameters

line: number

Returns

string


getRange()

abstract getRange(from, to): string

Parameters

from: EditorPosition

to: EditorPosition

Returns

string


getScrollInfo()

abstract getScrollInfo(): object

Returns

object

left

left: number

top

top: number


getSelection()

abstract getSelection(): string

Returns

string


getValue()

abstract getValue(): string

Returns

string


hasFocus()

abstract hasFocus(): boolean

Returns

boolean


hasHighlight()

hasHighlight(style?): boolean

Checks whether the editor has a highlight of specified class

Parameters

style?: string

Returns

boolean


indentList()

indentList(): void

Indents a list by one level

Returns

void

Inherited from

BaseEditor.indentList


insertBlock()

insertBlock(start, end): void

Wraps current line around specified characters

Parameters

start: string

end: string

Returns

void


insertCallout()

insertCallout(): void

Insert a template callout at the current cursor position

Returns

void

Inherited from

BaseEditor.insertCallout


insertCodeblock()

insertCodeblock(): void

Insert a template code block at the current cursor position

Returns

void

Inherited from

BaseEditor.insertCodeblock


insertLink(): void

Insert a markdown link at the current cursor position

Returns

void

Inherited from

BaseEditor.insertLink


insertMathJax()

insertMathJax(): void

Insert a mathjax equation block at the current cursor position

Returns

void

Inherited from

BaseEditor.insertMathJax


insertText()

insertText(text): void

Insert specified text at the current cursor position

Parameters

text: string

Returns

void

Inherited from

BaseEditor.insertText


lastLine()

abstract lastLine(): number

Returns

number


lineCount()

abstract lineCount(): number

Gets the number of lines in the document

Returns

number


listSelections()

abstract listSelections(): EditorSelection[]

Returns

EditorSelection[]


newlineAndIndentContinueMarkdownList()

newlineAndIndentContinueMarkdownList(): void

Inserts a new line and continues a markdown bullet point list at the same level

Returns

void

Inherited from

BaseEditor.newlineAndIndentContinueMarkdownList


newlineAndIndentOnly()

newlineAndIndentOnly(): void

Inserts a new line at the same indent level

Returns

void

Inherited from

BaseEditor.newlineAndIndentOnly


offsetToPos()

abstract offsetToPos(offset): EditorPosition

Parameters

offset: number

Returns

EditorPosition


posAtCoords()

posAtCoords(coords): EditorPosition

Get the closest character position to the specified coordinates

Parameters

coords

coords.left: number

coords.top: number

Returns

EditorPosition


posAtMouse()

posAtMouse(e): EditorPosition

Get the character position at a mouse event

Parameters

e: MouseEvent

Returns

EditorPosition

Inherited from

BaseEditor.posAtMouse


posToOffset()

abstract posToOffset(pos): number

Parameters

pos: EditorPosition

Returns

number


processLines()

processLines<T>(read, write, ignoreEmpty?): void

Type Parameters

T

Parameters

read

write

ignoreEmpty?: boolean

Returns

void


redo()

abstract redo(): void

Returns

void


refresh()

abstract refresh(): void

Returns

void


removeHighlights()

removeHighlights(style): void

Removes all highlights of specified class

Parameters

style: string

Returns

void


replaceRange()

abstract replaceRange(replacement, from, to?, origin?): void

Parameters

replacement: string

from: EditorPosition

to?: EditorPosition

origin?: string

Returns

void


replaceSelection()

abstract replaceSelection(replacement, origin?): void

Parameters

replacement: string

origin?: string

Returns

void


scrollIntoView()

abstract scrollIntoView(range, center?): void

Parameters

range: EditorRange

center?: boolean

Returns

void


scrollTo()

abstract scrollTo(x?, y?): void

Parameters

x?: null | number

y?: null | number

Returns

void


searchCursor()

searchCursor(searchString): SearchCursor

Adds a search cursor to the editor

Parameters

searchString: string

Returns

SearchCursor


setCursor()

setCursor(pos, ch?): void

Parameters

pos: number | EditorPosition

ch?: number

Returns

void


setLine()

setLine(n, text): void

Parameters

n: number

text: string

Returns

void


setSelection()

abstract setSelection(anchor, head?): void

Parameters

anchor: EditorPosition

head?: EditorPosition

Returns

void


setSelections()

abstract setSelections(ranges, main?): void

Parameters

ranges: EditorSelectionOrCaret[]

main?: number

Returns

void


setValue()

abstract setValue(content): void

Parameters

content: string

Returns

void


somethingSelected()

somethingSelected(): boolean

Returns

boolean


toggleBlockquote()

toggleBlockquote(): void

Toggles blockquote syntax on paragraph under cursor

Returns

void

Inherited from

BaseEditor.toggleBlockquote


toggleBulletList()

toggleBulletList(): void

Toggle bullet point list syntax on paragraph under cursor

Returns

void

Inherited from

BaseEditor.toggleBulletList


toggleCheckList()

toggleCheckList(): void

Toggle checkbox syntax on paragraph under cursor

Returns

void

Inherited from

BaseEditor.toggleCheckList


toggleMarkdownFormatting()

toggleMarkdownFormatting(syntax): void

Applies specified markdown syntax to selected text or word under cursor

Parameters

syntax: "bold" | "italic" | "strikethrough" | "highlight" | "code" | "math" | "comment"

Returns

void


toggleNumberList()

toggleNumberList(): void

Toggle numbered list syntax on paragraph under cursor

Returns

void

Inherited from

BaseEditor.toggleNumberList


transaction()

abstract transaction(tx, origin?): void

Parameters

tx: EditorTransaction

origin?: string

Returns

void


triggerWikiLink(embed): void

Convert word under cursor into a wikilink

Parameters

embed: boolean

Whether to embed the link or not

Returns

void

Inherited from

BaseEditor.triggerWikiLink


undo()

abstract undo(): void

Returns

void


unindentList()

unindentList(): void

Unindents a list by one level

Returns

void

Inherited from

BaseEditor.unindentList


wordAt()

abstract wordAt(pos): null | EditorRange

Parameters

pos: EditorPosition

Returns

null | EditorRange