CodeMirrorEditor
Unofficial
CM5-compatible editor interface wrapping a CodeMirror 6 editor view.
Import:
import type { CodeMirrorEditor } from '@obsidian-typings/obsidian-catalyst-latest';Signature:
export interface CodeMirrorEditorProperties
| Property | Type | Description | |
|---|---|---|---|
| $lineHandleChanges | LineHandleChange[] | undefined | Pending line handle changes to be processed. |
Methods
| Method | Returns | Description | |
|---|---|---|---|
| addOverlay(options) | SearchQuery | undefined | Add a search overlay to highlight matches in the editor. | |
| blur() | void | Remove focus from the editor. | |
| charCoords(pos, mode) | Coords | Get the pixel coordinates of a character position. | |
| clipPos(pos) | EditorPosition | Clip a position to be within the document bounds. | |
| coordsChar(coords, mode) | EditorPosition | Get the editor position corresponding to pixel coordinates. | |
| defaultTextHeight() | number | Get the default height of a line of text in pixels. | |
| destroy() | void | Destroy and clean up resources. | |
| execCommand(command) | void | Execute a named editor command. | |
| findMatchingBracket(pos) | MatchingBracket | Find the matching bracket for the bracket at the given position. | |
| findPosV(start, amount, unit, goalColumn) | EditorPosition | Find a position vertically relative to the given start position. | |
| firstLine() | number | Get the line number of the first line in the document. | |
| focus() | void | Focus the editor. | |
| foldCode(line) | void | Fold the code block at the given line. | |
| forEachSelection(fn) | void | Execute a function for each selection in a multi-selection. | |
| getCursor(type?) | EditorPosition | Get the cursor position, optionally specifying which end of the selection. | |
| getInputField() | HTMLElement | Get the editor's input field element. | |
| getLastEditEnd() | EditorPosition | Get the position of the last edit. | |
| getLine(line) | string | Get the text content of the given line number. | |
| getLineHandle(line) | LineHandle | Get a handle for the given line number. | |
| getLineNumber(handle) | null | number | Get the line number from a line handle, or null if the handle is invalid. | |
| getMainSelection() | EditorSelection | Get the primary selection as anchor and head positions. | |
| getMode() | CodeMirrorEditorMode | Get the current editor language mode. | |
| getOption(option) | unknown | Get the value of an editor option. | |
| getRange(from, to) | string | Get the text between two positions. | |
| getScrollInfo() | ScrollInfo | Get information about the editor's scroll position and dimensions. | |
| getSearchCursor(query, pos) | CodeMirrorEditorSearchCursor | Get a search cursor for the given regular expression starting at the given position. | |
| getSelection() | string | Get the currently selected text. | |
| getSelections() | string[] | Get all selections as an array of strings. | |
| getTokenTypeAt(pos) | string | Get the token type at the given position. | |
| getValue() | string | Get the full text content of the document. | |
| getWrapperElement() | HTMLElement | Get the outermost wrapper element of the editor. | |
| hardWrap(options) | void | Hard-wrap text according to the given options. | |
| indentLess() | void | Decrease the indentation of the selection. | |
| indentLine(line, more?) | void | Indent the given line, optionally adding more indentation. | |
| indentMore() | void | Increase the indentation of the selection. | |
| indexFromPos(pos) | number | Convert an editor position to a character index within the document. | |
| isInMultiSelectMode() | boolean | Check whether the editor is in multi-selection mode. | |
| lastLine() | number | Get the line number of the last line in the document. | |
| lineCount() | number | Get the total number of lines in the document. | |
| listSelections() | Array<CodeMirrorEditorSelectionRange> | Get all current selections as an array of anchor/head pairs. | |
| moveByChar(pos, dir, unit) | EditorPosition | Move a position by character in the given direction. | |
| moveH(dir, unit) | void | Move the cursor horizontally by the given number of units. | |
| off(event, listener) | void | Remove an event listener from the editor. | |
| on(event, listener) | void | Add an event listener to the editor. | |
| onBeforeEndOperation() | void | Handle pre-operation-end cleanup. | |
| onChange(lineHandleChange) | void | Handle a line handle change event. | |
| onSelectionChange() | void | Handle a selection change event. | |
| openDialog(template, keyValidator, options?) | void | Open an interactive dialog in the editor. | |
| openNotification(message, options?) | () => void | Open a notification message in the editor. Returns a function to dismiss it. | |
| operation(fn) | T | Execute a function as a single operation, batching view updates. | |
| overWriteSelection(text) | void | Overwrite the current selection with the given text. | |
| posFromIndex(index) | EditorPosition | Convert a character index to an editor position. | |
| refresh() | void | Refresh the editor display. | |
| releaseLineHandles() | void | Release all tracked line handles. | |
| removeOverlay(overlay?) | void | Remove a search overlay from the editor. | |
| replaceRange(text, from, to?) | void | Replace the text in the given range. | |
| replaceSelection(text) | void | Replace the current selection with the given text. | |
| replaceSelections(texts) | void | Replace all selections with the corresponding texts. | |
| scanForBracket(from, direction, style?) | Bracket | null | Scan for a bracket from the given position in the specified direction. | |
| scrollInfo() | ScrollInfo | Get information about the editor's scroll position and dimensions. | |
| scrollIntoView(pos?, margin?) | void | Scroll the given position into view with an optional margin. | |
| scrollTo(x?, y?) | void | Scroll the editor to the given coordinates. | |
| setBookmark(pos, options?) | Bookmark | Set a bookmark at the given position. | |
| setCursor(line, ch) | void | Set the cursor position to the given line and character. | |
| setOption(option, value) | void | Set the value of an editor option. | |
| setSelection(anchor, head, options?) | void | Set the selection to the given anchor and head positions. | |
| setSelections(selections, primaryIndex?) | void | Set multiple selections, optionally specifying the primary selection index. | |
| setSize(width, height) | void | Set the size of the editor in pixels. | |
| setValue(content) | void | Set the full text content of the document. | |
| signal(event, args?) | void | Emit a signal/event on the editor. | |
| somethingSelected() | boolean | Check whether there is an active selection. | |
| toggleOverwrite(overwrite) | void | Toggle overwrite mode on or off. | |
| virtualSelectionMode() | boolean | Check whether the editor is in virtual selection mode. |
Links to this page: