Skip to main content

Editor

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

Constructor

constructor();

Methods

getDoc

getDoc(): this;

refresh

abstract refresh(): void;

getValue

abstract getValue(): string;

setValue

abstract setValue(content: string): void;

getLine

abstract getLine(line: number): string;

Get the text at line (0-indexed)

setLine

setLine(n: number, text: string): void;

lineCount

abstract lineCount(): number;

Gets the number of lines in the document

lastLine

abstract lastLine(): number;

getSelection

abstract getSelection(): string;

somethingSelected

somethingSelected(): boolean;

getRange

abstract getRange(from: EditorPosition, to: EditorPosition): string;

replaceSelection

abstract replaceSelection(replacement: string, origin?: string): void;

replaceRange

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

getCursor

abstract getCursor(string?: 'from' | 'to' | 'head' | 'anchor'): EditorPosition;

listSelections

abstract listSelections(): EditorSelection[];

setCursor

setCursor(pos: EditorPosition | number, ch?: number): void;

setSelection

abstract setSelection(anchor: EditorPosition, head?: EditorPosition): void;

setSelections

abstract setSelections(ranges: EditorSelectionOrCaret[], main?: number): void;

focus

abstract focus(): void;

blur

abstract blur(): void;

hasFocus

abstract hasFocus(): boolean;

getScrollInfo

abstract getScrollInfo(): {
top: number;
left: number;
};

scrollTo

abstract scrollTo(x?: number | null, y?: number | null): void;

scrollIntoView

abstract scrollIntoView(range: EditorRange, center?: boolean): void;

undo

abstract undo(): void;

redo

abstract redo(): void;

exec

abstract exec(command: EditorCommandName): void;

transaction

abstract transaction(tx: EditorTransaction, origin?: string): void;

wordAt

abstract wordAt(pos: EditorPosition): EditorRange | null;

posToOffset

abstract posToOffset(pos: EditorPosition): number;

offsetToPos

abstract offsetToPos(offset: number): EditorPosition;

processLines

processLines<T>(read: (line: number, lineText: string) => T | null, write: (line: number, lineText: string, value: T | null) => EditorChange | void, ignoreEmpty?: boolean): void;