Skip to content

CodeMirrorEditor

Unofficial

CM5-compatible editor interface wrapping a CodeMirror 6 editor view.

Import:

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

Signature:

export interface CodeMirrorEditor

Properties

PropertyTypeDescription
$lastChangeEndOffsetnumberDocument offset the last change ended at.
$lineHandleChangesLineHandleChange[] | undefinedPending line handle changes to be processed.
$midnumberIdentifier distinguishing this adapter from the others in the workspace.
cm6EditorViewThe CodeMirror 6 view this adapter wraps.
curOpCodeMirrorEditorOperation | null | undefinedThe batch of work currently in progress, or null or undefined when none is.
marksRecord<string, Bookmark>The bookmarks set in this editor, keyed by their name.
optionsRecord<string, unknown>Options set on this adapter.
stateVimStateThe state bag other layers hang their per-editor data off, which is where Vim mode keeps its own.

Methods

MethodReturnsDescription
addOverlay(options)SearchQuery | undefinedAdd a search overlay to highlight matches in the editor.
blur()voidRemove focus from the editor.
charCoords(pos, mode?)CodeMirrorEditorCharCoordsGet the pixel coordinates of a character position.
clipPos(pos)EditorPositionClip a position to be within the document bounds.
coordsChar(coords, mode?)EditorPositionGet the editor position corresponding to pixel coordinates.
defaultTextHeight()numberGet the default height of a line of text in pixels.
destroy()voidDestroy and clean up resources.
editImage()voidOpen the editing prompt for the image the selection is on.
execCommand(command)voidExecute a named editor command.
findMatchingBracket(pos)MatchingBracketFind the matching bracket for the bracket at the given position.
findPosV(start, amount, unit, goalColumn)EditorPositionFind a position vertically relative to the given start position.
firstLine()numberGet the line number of the first line in the document.
focus()voidFocus the editor.
foldCode(line)voidFold the code block at the given line.
forEachSelection(fn)voidExecute a function for each selection in a multi-selection.
getCursor(type?)EditorPositionGet the cursor position, optionally specifying which end of the selection.
getDeletedText()null | stringGet the text deleted during the operation in progress.
getInputField()HTMLElementGet the editor's input field element.
getLastEditEnd()EditorPositionGet the position of the last edit.
getLine(line)stringGet the text content of the given line number.
getLineHandle(line)LineHandleGet a handle for the given line number.
getLineNumber(handle)null | numberGet the line number from a line handle, or null if the handle is invalid.
getMainSelection()EditorSelectionGet the primary selection as anchor and head positions.
getMode()CodeMirrorEditorModeGet the current editor language mode.
getOption(option)unknownGet the value of an editor option.
getRange(from, to)stringGet the text between two positions.
getScrollInfo()ScrollInfoGet information about the editor's scroll position and dimensions.
getSearchCursor(query, pos)CodeMirrorEditorSearchCursorGet a search cursor for the given regular expression starting at the given position.
getSelection()stringGet the currently selected text.
getSelections()string[]Get all selections as an array of strings.
getTokenTypeAt(pos)stringGet the token type at the given position.
getValue()stringGet the full text content of the document.
getWrapperElement()HTMLElementGet the outermost wrapper element of the editor.
hardWrap(options)voidHard-wrap text according to the given options.
indentLess()voidDecrease the indentation of the selection.
indentLine(line, more?)voidIndent the given line, optionally adding more indentation.
indentMore()voidIncrease the indentation of the selection.
indexFromPos(pos)numberConvert an editor position to a character index within the document.
isInMultiSelectMode()booleanCheck whether the editor is in multi-selection mode.
lastLine()numberGet the line number of the last line in the document.
lineCount()numberGet the total number of lines in the document.
listSelections()Array<CodeMirrorEditorSelectionRange>Get all current selections as an array of anchor/head pairs.
mapPos(pos, assoc?)EditorPositionMap a position taken before the changes made during the operation in progress onto where it sits after them.
moveByChar(pos, dir, unit)EditorPositionMove a position by character in the given direction.
moveH(dir, unit)voidMove the cursor horizontally by the given number of units.
off(event, listener)voidRemove an event listener from the editor.
on(event, listener)voidAdd an event listener to the editor.
onBeforeEndOperation()voidHandle pre-operation-end cleanup.
onChange(lineHandleChange)voidHandle a line handle change event.
onSelectionChange()voidHandle a selection change event.
openDialog(template, keyValidator, options?)voidOpen an interactive dialog in the editor.
openNotification(message, options?)() => voidOpen a notification message in the editor. Returns a function to dismiss it.
operation(fn, force?)TRun a function as one batch of work, so the editor only reacts to what it did once it finishes. Nesting is allowed — only the outermost call ends the batch.
operation(fn)TExecute a function as a single operation, batching view updates.
overWriteSelection(text)voidOverwrite the current selection with the given text.
posFromIndex(index)EditorPositionConvert a character index to an editor position.
refresh()voidRefresh the editor display.
releaseLineHandles()voidRelease all tracked line handles.
removeOverlay(overlay?)voidRemove a search overlay from the editor.
replaceRange(text, from, to?)voidReplace the text in the given range.
replaceSelection(text)voidReplace the current selection with the given text.
replaceSelections(texts)voidReplace all selections with the corresponding texts.
resetImageSize()voidRestore the image the selection is on to its natural size.
resizeImage(delta, step?)voidResize the image the selection is on.
scanForBracket(from, direction, style?)Bracket | nullScan for a bracket from the given position in the specified direction.
scrollInfo()ScrollInfoGet information about the editor's scroll position and dimensions.
scrollIntoView(pos?, margin?)voidScroll the given position into view with an optional margin.
scrollTo(x?, y?)voidScroll the editor to the given coordinates.
setBookmark(pos, options?)BookmarkSet a bookmark at the given position.
setCursor(line, ch)voidSet the cursor position to the given line and character.
setOption(option, value)voidSet the value of an editor option.
setSelection(anchor, head, options?)voidSet the selection to the given anchor and head positions.
setSelections(selections, primaryIndex?)voidSet multiple selections, optionally specifying the primary selection index.
setSize(width, height)voidSet the size of the editor in pixels.
setValue(content)voidSet the full text content of the document.
signal(event, args?)voidEmit a signal/event on the editor.
somethingSelected()booleanCheck whether there is an active selection.
toggleOverwrite(overwrite)voidToggle overwrite mode on or off.
tryHandleKey(key)booleanGive the live preview layer a chance to handle a key before Vim mode does, which is how the horizontal motions step in and out of a rendered element.
virtualSelectionMode()booleanCheck whether the editor is in virtual selection mode.

Links to this page: