UNPKG

98 kBTypeScriptView Raw
1// Type definitions for codemirror 5.60
2// Project: https://github.com/codemirror/CodeMirror
3// Definitions by: mihailik <https://github.com/mihailik>
4// nrbernard <https://github.com/nrbernard>
5// Pr1st0n <https://github.com/Pr1st0n>
6// rileymiller <https://github.com/rileymiller>
7// toddself <https://github.com/toddself>
8// ysulyma <https://github.com/ysulyma>
9// azoson <https://github.com/azoson>
10// kylesferrazza <https://github.com/kylesferrazza>
11// fityocsaba96 <https://github.com/fityocsaba96>
12// koddsson <https://github.com/koddsson>
13// ficristo <https://github.com/ficristo>
14// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
15// TypeScript Version: 3.8
16
17export = CodeMirror;
18export as namespace CodeMirror;
19
20declare function CodeMirror(place: ParentNode | ((host: HTMLElement) => void), options?: CodeMirror.EditorConfiguration): CodeMirror.Editor;
21
22declare namespace CodeMirror {
23 const Doc: DocConstructor;
24 const Pos: PositionConstructor;
25 const Pass: { toString(): 'CodeMirror.PASS' };
26
27 /** Find the column position at a given string index using a given tabsize. */
28 function countColumn(line: string, index: number | null, tabSize: number): number;
29 function fromTextArea(host: HTMLTextAreaElement, options?: EditorConfiguration): EditorFromTextArea;
30
31 /** Split a string by new line. */
32 function splitLines(text: string): string[];
33
34 /** Check if a char is part of an alphabet. */
35 function isWordChar(ch: string): boolean;
36
37 /** Call startState of the mode if available, otherwise return true */
38 function startState<T>(mode: Mode<T>, a1?: any, a2?: any): T | boolean;
39
40 /** Compare two positions, return 0 if they are the same, a negative number when a is less, and a positive number otherwise. */
41 function cmpPos(a: Position, b: Position): number;
42
43 /**
44 * Utility function that computes an end position from a change (an object with from, to, and text properties, as passed to various event handlers).
45 * The returned position will be the end of the changed range, after the change is applied.
46 */
47 function changeEnd(change: EditorChange): Position;
48
49 /**
50 * It contains a string that indicates the version of the library. This is a triple of integers "major.minor.patch",
51 * where patch is zero for releases, and something else (usually one) for dev snapshots.
52 */
53 const version: string;
54
55 /**
56 * An object containing default values for all options.
57 * You can assign to its properties to modify defaults (though this won't affect editors that have already been created).
58 */
59 const defaults: {
60 [option: string]: any;
61 };
62
63 /**
64 * If you want to define extra methods in terms of the CodeMirror API, it is possible to use defineExtension.
65 * This will cause the given value(usually a method) to be added to all CodeMirror instances created from then on.
66 */
67 function defineExtension(name: string, value: any): void;
68
69 /** Like defineExtension, but the method will be added to the interface for Doc objects instead. */
70 function defineDocExtension(name: string, value: any): void;
71
72 /**
73 * Similarly, defineOption can be used to define new options for CodeMirror.
74 * The updateFunc will be called with the editor instance and the new value when an editor is initialized,
75 * and whenever the option is modified through setOption.
76 */
77 function defineOption(name: string, default_: any, updateFunc: (editor: Editor, val: any, old: any) => void): void;
78
79 /**
80 * If your extension just needs to run some code whenever a CodeMirror instance is initialized, use CodeMirror.defineInitHook.
81 * Give it a function as its only argument, and from then on, that function will be called (with the instance as argument)
82 * whenever a new CodeMirror instance is initialized.
83 */
84 function defineInitHook(func: (editor: Editor) => void): void;
85
86 /**
87 * Registers a helper value with the given name in the given namespace (type). This is used to define functionality
88 * that may be looked up by mode. Will create (if it doesn't already exist) a property on the CodeMirror object for
89 * the given type, pointing to an object that maps names to values. I.e. after doing
90 * CodeMirror.registerHelper("hint", "foo", myFoo), the value CodeMirror.hint.foo will point to myFoo.
91 */
92 function registerHelper(namespace: string, name: string, helper: any): void;
93
94 /** Given a state object, returns a {state, mode} object with the inner mode and its state for the current position. */
95 function innerMode(mode: Mode<any>, state: any): { state: any; mode: Mode<any> };
96
97 /**
98 * Sometimes, it is useful to add or override mode object properties from external code.
99 * The CodeMirror.extendMode function can be used to add properties to mode objects produced for a specific mode.
100 * Its first argument is the name of the mode, its second an object that specifies the properties that should be added.
101 * This is mostly useful to add utilities that can later be looked up through getMode.
102 */
103 function extendMode(name: string, properties: Partial<Mode<any>>): void;
104
105 interface EditorEventMap {
106 change: (instance: Editor, changeObj: EditorChange) => void;
107 changes: (instance: Editor, changes: EditorChange[]) => void;
108 beforeChange: (instance: Editor, changeObj: EditorChangeCancellable) => void;
109 cursorActivity: (instance: Editor) => void;
110 keyHandled: (instance: Editor, name: string, event: Event) => void;
111 inputRead: (instance: Editor, changeObj: EditorChange) => void;
112 electricInput: (instance: Editor, line: number) => void;
113 beforeSelectionChange: (instance: Editor, obj: EditorSelectionChange) => void;
114 viewportChange: (instance: Editor, from: number, to: number) => void;
115 swapDoc: (instance: Editor, oldDoc: Doc) => void;
116 gutterClick: (instance: Editor, line: number, gutter: string, clickEvent: Event) => void;
117 gutterContextMenu: (instance: Editor, line: number, gutter: string, contextMenuEvent: MouseEvent) => void;
118 focus: (instance: Editor, event: FocusEvent) => void;
119 blur: (instance: Editor, event: FocusEvent) => void;
120 scroll: (instance: Editor) => void;
121 refresh: (instance: Editor) => void;
122 optionChange: (instance: Editor, option: keyof EditorConfiguration) => void;
123 scrollCursorIntoView: (instance: Editor, event: Event) => void;
124 update: (instance: Editor) => void;
125 renderLine: (instance: Editor, lineHandle: LineHandle, element: HTMLElement) => void;
126 overwriteToggle: (instance: Editor, overwrite: boolean) => void;
127 }
128
129 interface DocEventMap {
130 change: (instance: Doc, changeObj: EditorChange) => void;
131 beforeChange: (instance: Doc, changeObj: EditorChangeCancellable) => void;
132 cursorActivity: (instance: Doc) => void;
133 beforeSelectionChange: (instance: Doc, obj: EditorSelectionChange) => void;
134 }
135
136 interface LineHandleEventMap {
137 delete: () => void;
138 change: (instance: LineHandle, changeObj: EditorChange) => void;
139 }
140
141 interface TextMarkerEventMap {
142 beforeCursorEnter: () => void;
143 clear: (from: Position, to: Position) => void;
144 hide: () => void;
145 unhide: () => void;
146 }
147
148 interface LineWidgetEventMap {
149 redraw: () => void;
150 }
151
152 function on<T extends keyof DocEventMap>(doc: Doc, eventName: T, handler: DocEventMap[T]): void;
153 function on<T extends keyof EditorEventMap>(cm: Editor, eventName: T, handler: EditorEventMap[T]): void;
154 function on<T extends keyof LineHandleEventMap>(lineHandle: LineHandle, eventName: T, handler: LineHandleEventMap[T]): void;
155 function on<T extends keyof TextMarkerEventMap>(textMarker: TextMarker<unknown>, eventName: T, handler: TextMarkerEventMap[T]): void;
156 function on<T extends keyof LineWidgetEventMap>(LineWidget: LineWidget, eventName: T, handler: LineWidgetEventMap[T]): void;
157 function on(element: any, eventName: string, handler: () => void): void;
158
159 function off<T extends keyof DocEventMap>(doc: Doc, eventName: T, handler: DocEventMap[T]): void;
160 function off<T extends keyof EditorEventMap>(cm: Editor, eventName: T, handler: EditorEventMap[T]): void;
161 function off<T extends keyof LineHandleEventMap>(lineHandle: LineHandle, eventName: T, handler: LineHandleEventMap[T]): void;
162 function off<T extends keyof TextMarkerEventMap>(textMarker: TextMarker<unknown>, eventName: T, handler: TextMarkerEventMap[T]): void;
163 function off<T extends keyof LineWidgetEventMap>(lineWidget: LineWidget, eventName: T, handler: LineWidgetEventMap[T]): void;
164 function off(element: any, eventName: string, handler: () => void): void;
165
166 /**
167 * Various CodeMirror-related objects emit events, which allow client code to react to various situations.
168 * Handlers for such events can be registered with the on and off methods on the objects that the event fires on.
169 * To fire your own events, use CodeMirror.signal(target, name, args...), where target is a non-DOM-node object.
170 */
171 function signal<T extends keyof DocEventMap>(doc: Doc, eventName: T, ...args: Parameters<DocEventMap[T]>): void;
172 function signal<T extends keyof EditorEventMap>(cm: Editor, eventName: T, ...args: Parameters<EditorEventMap[T]>): void;
173 function signal<T extends keyof LineHandleEventMap>(lineHandle: LineHandle, eventName: T, ...args: Parameters<LineHandleEventMap[T]>): void;
174 function signal<T extends keyof TextMarkerEventMap>(textMarker: TextMarker<unknown>, eventName: T, ...args: Parameters<TextMarkerEventMap[T]>): void;
175 function signal<T extends keyof LineWidgetEventMap>(lineWidget: LineWidget, eventName: T, ...args: Parameters<LineWidgetEventMap[T]>): void;
176 function signal(target: any, name: string, ...args: any[]): void;
177
178 /** Modify a keymap to normalize modifier order and properly recognize multi-stroke bindings. */
179 function normalizeKeyMap(km: KeyMap): KeyMap;
180
181 type DOMEvent =
182 | 'mousedown'
183 | 'dblclick'
184 | 'touchstart'
185 | 'contextmenu'
186 | 'keydown'
187 | 'keypress'
188 | 'keyup'
189 | 'cut'
190 | 'copy'
191 | 'paste'
192 | 'dragstart'
193 | 'dragenter'
194 | 'dragover'
195 | 'dragleave'
196 | 'drop';
197
198 type CoordsMode = 'window' | 'page' | 'local' | 'div';
199
200 interface Token {
201 /** The character(on the given line) at which the token starts. */
202 start: number;
203 /** The character at which the token ends. */
204 end: number;
205 /** The token's string. */
206 string: string;
207 /** The token type the mode assigned to the token, such as "keyword" or "comment" (may also be null). */
208 type: string | null;
209 /** The mode's state at the end of this token. */
210 state: any;
211 }
212
213 interface KeyMap {
214 [keyName: string]: false | string | ((instance: Editor) => void | typeof Pass);
215 }
216
217 /**
218 * Methods prefixed with doc. can, unless otherwise specified, be called both on CodeMirror (editor) instances and
219 * CodeMirror.Doc instances. Thus, the Editor interface extends DocOrEditor defining the common API.
220 */
221 interface Editor extends DocOrEditor {
222 /** Tells you whether the editor currently has focus. */
223 hasFocus(): boolean;
224
225 /**
226 * Used to find the target position for horizontal cursor motion.start is a { line , ch } object,
227 * an integer(may be negative), and unit one of the string "char", "column", or "word".
228 * Will return a position that is produced by moving amount times the distance specified by unit.
229 * When visually is true , motion in right - to - left text will be visual rather than logical.
230 * When the motion was clipped by hitting the end or start of the document, the returned value will have a hitSide property set to true.
231 */
232 findPosH(
233 start: Position,
234 amount: number,
235 unit: string,
236 visually: boolean,
237 ): { line: number; ch: number; hitSide?: boolean | undefined };
238
239 /**
240 * Similar to findPosH , but used for vertical motion.unit may be "line" or "page".
241 * The other arguments and the returned value have the same interpretation as they have in findPosH.
242 */
243 findPosV(
244 start: Position,
245 amount: number,
246 unit: string,
247 ): { line: number; ch: number; hitSide?: boolean | undefined };
248
249 /** Returns the start and end of the 'word' (the stretch of letters, whitespace, or punctuation) at the given position. */
250 findWordAt(pos: Position): Range;
251
252 /** Change the configuration of the editor. option should the name of an option, and value should be a valid value for that option. */
253 setOption<K extends keyof EditorConfiguration>(option: K, value: EditorConfiguration[K]): void;
254
255 /** Retrieves the current value of the given option for this editor instance. */
256 getOption<K extends keyof EditorConfiguration>(option: K): EditorConfiguration[K];
257
258 /**
259 * Attach an additional keymap to the editor.
260 * This is mostly useful for add - ons that need to register some key handlers without trampling on the extraKeys option.
261 * Maps added in this way have a higher precedence than the extraKeys and keyMap options, and between them,
262 * the maps added earlier have a lower precedence than those added later, unless the bottom argument was passed,
263 * in which case they end up below other keymaps added with this method.
264 */
265 addKeyMap(map: string | KeyMap, bottom?: boolean): void;
266
267 /**
268 * Disable a keymap added with addKeyMap.Either pass in the keymap object itself , or a string,
269 * which will be compared against the name property of the active keymaps.
270 */
271 removeKeyMap(map: string | KeyMap): void;
272
273 /**
274 * Enable a highlighting overlay.This is a stateless mini-mode that can be used to add extra highlighting.
275 * For example, the search add - on uses it to highlight the term that's currently being searched.
276 * mode can be a mode spec or a mode object (an object with a token method). The options parameter is optional. If given, it should be an object.
277 * Currently, only the opaque option is recognized. This defaults to off, but can be given to allow the overlay styling, when not null,
278 * to override the styling of the base mode entirely, instead of the two being applied together.
279 */
280 addOverlay(mode: any, options?: {opaque?: boolean | undefined, priority?: number | undefined}): void;
281
282 /** Pass this the exact argument passed for the mode parameter to addOverlay to remove an overlay again. */
283 removeOverlay(mode: any): void;
284
285 /** Retrieve the currently active document from an editor. */
286 getDoc(): Doc;
287
288 /** Attach a new document to the editor. Returns the old document, which is now no longer associated with an editor. */
289 swapDoc(doc: Doc): Doc;
290
291 /** Get the content of the current editor document. You can pass it an optional argument to specify the string to be used to separate lines (defaults to "\n"). */
292 getValue(seperator?: string): string;
293
294 /** Set the content of the current editor document. */
295 setValue(content: string): void;
296
297 /**
298 * start is a an optional string indicating which end of the selection to return.
299 * It may be "from", "to", "head" (the side of the selection that moves when you press shift+arrow),
300 * or "anchor" (the fixed side of the selection).Omitting the argument is the same as passing "head". A {line, ch} object will be returned.
301 */
302 getCursor(start?: string): Position;
303
304 /**
305 * Set the cursor position. You can either pass a single {line, ch} object, or the line and the character as two separate parameters.
306 * Will replace all selections with a single, empty selection at the given position.
307 * The supported options are the same as for setSelection
308 */
309 setCursor(
310 pos: Position | number,
311 ch?: number,
312 options?: { bias?: number | undefined; origin?: string | undefined; scroll?: boolean | undefined },
313 ): void;
314
315 /**
316 * Sets the gutter marker for the given gutter (identified by its CSS class, see the gutters option) to the given value.
317 * Value can be either null, to clear the marker, or a DOM element, to set it. The DOM element will be shown in the specified gutter next to the specified line.
318 */
319 setGutterMarker(line: any, gutterID: string, value: HTMLElement | null): LineHandle;
320
321 /** Remove all gutter markers in the gutter with the given ID. */
322 clearGutter(gutterID: string): void;
323
324 /**
325 * Set a CSS class name for the given line.line can be a number or a line handle.
326 * where determines to which element this class should be applied, can can be one of "text" (the text element, which lies in front of the selection),
327 * "background"(a background element that will be behind the selection),
328 * or "wrap" (the wrapper node that wraps all of the line's elements, including gutter elements).
329 * class should be the name of the class to apply.
330 */
331 addLineClass(line: any, where: string, _class_: string): LineHandle;
332
333 /**
334 * Remove a CSS class from a line.line can be a line handle or number.
335 * where should be one of "text", "background", or "wrap"(see addLineClass).
336 * class can be left off to remove all classes for the specified node, or be a string to remove only a specific class.
337 */
338 removeLineClass(line: any, where: string, class_?: string): LineHandle;
339
340 /**
341 * Compute the line at the given pixel height. mode is the relative element
342 * to use to compute this line, it may be "window", "page" (the default), or "local"
343 */
344 lineAtHeight(height: number, mode?: CoordsMode): number;
345
346 /**
347 * Computes the height of the top of a line, in the coordinate system specified by mode, it may be "window",
348 * "page" (the default), or "local". When a line below the bottom of the document is specified, the returned value
349 * is the bottom of the last line in the document. By default, the position of the actual text is returned.
350 * If includeWidgets is true and the line has line widgets, the position above the first line widget is returned.
351 */
352 heightAtLine(line: any, mode?: CoordsMode, includeWidgets?: boolean): number;
353
354 /** Returns the line number, text content, and marker status of the given line, which can be either a number or a line handle. */
355 lineInfo(
356 line: any,
357 ): {
358 line: any;
359 handle: any;
360 text: string;
361 /** Object mapping gutter IDs to marker elements. */
362 gutterMarkers: any;
363 textClass: string;
364 bgClass: string;
365 wrapClass: string;
366 /** Array of line widgets attached to this line. */
367 widgets: any;
368 };
369
370 /**
371 * Puts node, which should be an absolutely positioned DOM node, into the editor, positioned right below the given { line , ch } position.
372 * When scrollIntoView is true, the editor will ensure that the entire node is visible (if possible).
373 * To remove the widget again, simply use DOM methods (move it somewhere else, or call removeChild on its parent).
374 */
375 addWidget(pos: Position, node: HTMLElement, scrollIntoView: boolean): void;
376
377 /**
378 * Adds a line widget, an element shown below a line, spanning the whole of the editor's width, and moving the lines below it downwards.
379 * line should be either an integer or a line handle, and node should be a DOM node, which will be displayed below the given line.
380 * options, when given, should be an object that configures the behavior of the widget.
381 * Note that the widget node will become a descendant of nodes with CodeMirror-specific CSS classes, and those classes might in some cases affect it.
382 */
383 addLineWidget(line: any, node: HTMLElement, options?: LineWidgetOptions): LineWidget;
384
385 /**
386 * Programatically set the size of the editor (overriding the applicable CSS rules).
387 * width and height height can be either numbers(interpreted as pixels) or CSS units ("100%", for example).
388 * You can pass null for either of them to indicate that that dimension should not be changed.
389 */
390 setSize(width: any, height: any): void;
391
392 /** Scroll the editor to a given(pixel) position.Both arguments may be left as null or undefined to have no effect. */
393 scrollTo(x?: number | null, y?: number | null): void;
394
395 /**
396 * Get an { left , top , width , height , clientWidth , clientHeight } object that represents the current scroll position, the size of the scrollable area,
397 * and the size of the visible area(minus scrollbars).
398 */
399 getScrollInfo(): ScrollInfo;
400
401 /**
402 * Scrolls the given element into view.
403 * pos can be:
404 * - a { line , ch } position, referring to a given character
405 * - null, to refer to the cursor
406 * - a { left , top , right , bottom } object, in editor-local coordinates
407 * - a { from, to } object, in editor-local coordinates
408 * The margin parameter is optional. When given, it indicates the amount of pixels around the given area that should be made visible as well.
409 */
410 scrollIntoView(
411 pos: Position | null | { line: number; ch: number } | { left: number; top: number; right: number; bottom: number } | { from: Position; to: Position },
412 margin?: number
413 ): void;
414
415 /**
416 * Returns an { left , top , bottom } object containing the coordinates of the cursor position.
417 * If mode is "local", they will be relative to the top-left corner of the editable document.
418 * If it is "page" or not given, they are relative to the top-left corner of the page.
419 * where specifies the position at which you want to measure. A boolean indicates either the start(true) or the end(false) of the selection.
420 */
421 cursorCoords(where?: boolean | Position | null, mode?: CoordsMode): { left: number; top: number; bottom: number };
422
423 /**
424 * Returns the position and dimensions of an arbitrary character. pos should be a { line , ch } object.
425 * If mode is "local", they will be relative to the top-left corner of the editable document.
426 * If it is "page" or not given, they are relative to the top-left corner of the page.
427 * This differs from cursorCoords in that it'll give the size of the whole character,
428 * rather than just the position that the cursor would have when it would sit at that position.
429 */
430 charCoords(
431 pos: Position,
432 mode?: CoordsMode,
433 ): { left: number; right: number; top: number; bottom: number };
434
435 /**
436 * Given an { left , top } object , returns the { line , ch } position that corresponds to it.
437 * The optional mode parameter determines relative to what the coordinates are interpreted.
438 * It may be "window", "page" (the default), or "local".
439 */
440 coordsChar(object: { left: number; top: number }, mode?: CoordsMode): Position;
441
442 /** Returns the line height of the default font for the editor. */
443 defaultTextHeight(): number;
444
445 /**
446 * Returns the pixel width of an 'x' in the default font for the editor.
447 * (Note that for non-monospace fonts, this is mostly useless, and even for monospace fonts, non-ascii characters might have a different width).
448 */
449 defaultCharWidth(): number;
450
451 /**
452 * Returns a { from , to } object indicating the start (inclusive) and end (exclusive) of the currently rendered part of the document.
453 * In big documents, when most content is scrolled out of view, CodeMirror will only render the visible part, and a margin around it.
454 * See also the viewportChange event.
455 */
456 getViewport(): { from: number; to: number };
457
458 /**
459 * If your code does something to change the size of the editor element (window resizes are already listened for), or unhides it,
460 * you should probably follow up by calling this method to ensure CodeMirror is still looking as intended.
461 */
462 refresh(): void;
463
464 /** Gets the inner mode at a given position. This will return the same as getMode for simple modes, but will return an inner mode for nesting modes (such as htmlmixed). */
465 getModeAt(pos: Position): Mode<unknown>;
466
467 /** Retrieves information about the token the current mode found before the given position (a {line, ch} object). */
468 getTokenAt(pos: Position, precise?: boolean): Token;
469
470 /**
471 * This is a (much) cheaper version of getTokenAt useful for when you just need the type of the token at a given position,
472 * and no other information. Will return null for unstyled tokens, and a string, potentially containing multiple
473 * space-separated style names, otherwise.
474 */
475 getTokenTypeAt(pos: Position): string;
476
477 /** This is similar to getTokenAt, but collects all tokens for a given line into an array. */
478 getLineTokens(line: number, precise?: boolean): Token[];
479
480 /**
481 * Returns the mode's parser state, if any, at the end of the given line number.
482 * If no line number is given, the state at the end of the document is returned.
483 * This can be useful for storing parsing errors in the state, or getting other kinds of contextual information for a line.
484 */
485 getStateAfter(line?: number): any;
486
487 /**
488 * CodeMirror internally buffers changes and only updates its DOM structure after it has finished performing some operation.
489 * If you need to perform a lot of operations on a CodeMirror instance, you can call this method with a function argument.
490 * It will call the function, buffering up all changes, and only doing the expensive update after the function returns.
491 * This can be a lot faster. The return value from this method will be the return value of your function.
492 */
493 operation<T>(fn: () => T): T;
494
495 /**
496 * In normal circumstances, use the above operation method. But if you want to buffer operations happening asynchronously, or that can't all be wrapped in a callback
497 * function, you can call startOperation to tell CodeMirror to start buffering changes, and endOperation to actually render all the updates. Be careful: if you use this
498 * API and forget to call endOperation, the editor will just never update.
499 */
500 startOperation(): void;
501 endOperation(): void;
502
503 /**
504 * Adjust the indentation of the given line.
505 * The second argument (which defaults to "smart") may be one of:
506 * "prev" Base indentation on the indentation of the previous line.
507 * "smart" Use the mode's smart indentation if available, behave like "prev" otherwise.
508 * "add" Increase the indentation of the line by one indent unit.
509 * "subtract" Reduce the indentation of the line.
510 */
511 indentLine(line: number, dir?: string): void;
512
513 /** Indent a selection */
514 indentSelection(how: string): void;
515
516 /** Tells you whether the editor's content can be edited by the user. */
517 isReadOnly(): boolean;
518
519 /**
520 * Switches between overwrite and normal insert mode (when not given an argument),
521 * or sets the overwrite mode to a specific state (when given an argument).
522 */
523 toggleOverwrite(value?: boolean): void;
524
525 /** Runs the command with the given name on the editor. */
526 execCommand(name: string): void;
527
528 /** Give the editor focus. */
529 focus(): void;
530
531 /**
532 * Allow the given string to be translated with the phrases option.
533 */
534 phrase(text: string): unknown;
535
536 /** Returns the hidden textarea used to read input. */
537 getInputField(): HTMLTextAreaElement;
538
539 /** Returns the DOM node that represents the editor, and controls its size. Remove this from your tree to delete an editor instance. */
540 getWrapperElement(): HTMLElement;
541
542 /** Returns the DOM node that is responsible for the scrolling of the editor. */
543 getScrollerElement(): HTMLElement;
544
545 /** Fetches the DOM node that contains the editor gutters. */
546 getGutterElement(): HTMLElement;
547
548 on<T extends keyof EditorEventMap>(eventName: T, handler: EditorEventMap[T]): void;
549 on<K extends DOMEvent & keyof GlobalEventHandlersEventMap>(
550 eventName: K,
551 handler: (instance: Editor, event: GlobalEventHandlersEventMap[K]) => void,
552 ): void;
553 on<K extends DOMEvent & keyof DocumentAndElementEventHandlersEventMap>(
554 eventName: K,
555 handler: (instance: Editor, event: DocumentAndElementEventHandlersEventMap[K]) => void,
556 ): void;
557
558 off<T extends keyof EditorEventMap>(eventName: T, handler: EditorEventMap[T]): void;
559 off<K extends DOMEvent & keyof GlobalEventHandlersEventMap>(
560 eventName: K,
561 handler: (instance: Editor, event: GlobalEventHandlersEventMap[K]) => void,
562 ): void;
563 off<K extends DOMEvent & keyof DocumentAndElementEventHandlersEventMap>(
564 eventName: K,
565 handler: (instance: Editor, event: DocumentAndElementEventHandlersEventMap[K]) => void,
566 ): void;
567
568 /** Expose the state object, so that the Editor.state.completionActive property is reachable */
569 state: any;
570 }
571
572 interface EditorFromTextArea extends Editor {
573 /** Copy the content of the editor into the textarea. */
574 save(): void;
575
576 /** Remove the editor, and restore the original textarea (with the editor's current content). */
577 toTextArea(): void;
578
579 /** Returns the textarea that the instance was based on. */
580 getTextArea(): HTMLTextAreaElement;
581 }
582
583 interface ModeSpecOptions {
584 /** Below options are supported in CSS mode */
585
586 /** Whether to highlight non-standard CSS property keywords such as margin-inline or zoom (default: true). */
587 highlightNonStandardPropertyKeywords?: boolean | undefined;
588
589 /** Below options are supported in Cython/Python modes */
590
591 /** The version of Python to recognize. Default is 3. */
592 version?: 2 | 3 | undefined;
593 /**
594 * If you have a single-line string that is not terminated at the end of the line, this will show subsequent
595 * lines as errors if true, otherwise it will consider the newline as the end of the string. Default is false.
596 */
597 singleLineStringErrors?: boolean | undefined;
598 /**
599 * If you want to write long arguments to a function starting on a new line, how much that line should be
600 * indented. Defaults to one normal indentation unit.
601 */
602 hangingIndent?: number | undefined;
603 /** Regular Expression for single operator matching */
604 singleOperators?: unknown | undefined;
605 /** Regular Expression for single delimiter matching default :^[\\(\\)\\[\\]\\{\\}@,:`=;\\.] */
606 singleDelimiters?: unknown | undefined;
607 /** Regular Expression for double operators matching, default :^((==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//)|(\\*\\*)) */
608 doubleOperators?: unknown | undefined;
609 /** Regular Expression for double delimiters matching default :^((\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=)) */
610 doubleDelimiters?: unknown | undefined;
611 /** Regular Expression for triple delimiters matching default :^((//=)|(>>=)|(<<=)|(\\*\\*=)) */
612 tripleDelimiters?: unknown | undefined;
613 /** RegEx - Regular Expression for identifier, default :^[_A-Za-z][_A-Za-z0-9]* */
614 identifiers?: unknown | undefined;
615 /** List of extra words ton consider as keywords */
616 extra_keywords?: string[] | undefined;
617 /** List of extra words ton consider as builtins */
618 extra_builtins?: string[] | undefined;
619
620 /** useCPP, which determines whether C preprocessor directives are recognized. */
621 useCPP?: boolean | undefined;
622
623 /** Below options are supported in Handlebars/Haskell/YAML front matter mode */
624 base?: string | undefined;
625
626 /** Below options are supported in HTML mixed mode */
627 tags?: {[key: string]: unknown} | undefined;
628
629 /** Below options are supported in JavaScript mixed mode */
630
631 /** json which will set the mode to expect JSON data rather than a JavaScript program. */
632 json?: boolean | undefined;
633 /** jsonld which will set the mode to expect JSON-LD linked data rather than a JavaScript program */
634 jsonld?: boolean | undefined;
635 /** typescript which will activate additional syntax highlighting and some other things for TypeScript code */
636 typescript?: boolean | undefined;
637 /**
638 * trackScope can be set to false to turn off tracking of local variables. This will prevent locals from getting
639 * the "variable-2" token type, and will break completion of locals with javascript-hint.
640 */
641 trackScope?: boolean | undefined;
642 /**
643 * statementIndent which (given a number) will determine the amount of indentation to use for statements
644 * continued on a new line.
645 */
646 statementIndent?: boolean | undefined;
647 /**
648 * wordCharacters, a regexp that indicates which characters should be considered part of an identifier.
649 * Defaults to /[\w$]/, which does not handle non-ASCII identifiers. Can be set to something more elaborate to
650 * improve Unicode support.
651 */
652 wordCharacters?: unknown | undefined;
653
654 /** Below options are supported in Markdown mixed mode */
655
656 /** Whether to separately highlight markdown meta characters (*[]()etc.) (default: false). */
657 highlightFormatting?: boolean | undefined;
658 /** Maximum allowed blockquote nesting (default: 0 - infinite nesting). */
659 maxBlockquoteDepth?: boolean | undefined;
660 /** Whether to highlight inline XML (default: true). */
661 xml?: boolean | undefined;
662 /**
663 * Whether to syntax-highlight fenced code blocks, if given mode is included, or fencedCodeBlockDefaultMode
664 * is set (default: true).
665 */
666 fencedCodeBlockHighlighting?: boolean | undefined;
667 /** Mode to use for fencedCodeBlockHighlighting, if given mode is not included. */
668 fencedCodeBlockDefaultMode?: string | undefined;
669 /** When you want to override default token type names (e.g. {code: "code"}). */
670 tokenTypeOverrides?: unknown | undefined;
671 /** Allow lazy headers without whitespace between hashtag and text (default: false). */
672 allowAtxHeaderWithoutSpace?: boolean | undefined;
673
674 /** Below options are supported in GFM mode mode */
675 gitHubSpice?: boolean | undefined;
676 taskLists?: boolean | undefined;
677 strikethrough?: boolean | undefined;
678 emoji?: boolean | undefined;
679
680 /** Below options are supported in Smarty mode */
681
682 /** leftDelimiter and rightDelimiter, which should be strings that determine where the Smarty syntax starts and ends. */
683 leftDelimiter?: string | undefined;
684 rightDelimiter?: string | undefined;
685 baseMode?: string | undefined;
686
687 /** Below options are supported in sTeX mode */
688
689 /** Whether to start parsing in math mode (default: false) */
690 inMathMode?: boolean | undefined;
691
692 /** Below options are supported in SystemVerilog mode */
693
694 /** List of keywords which should not cause indentation to increase. */
695 noIndentKeywords?: unknown | undefined;
696
697 /** Below options are supported in VHDL mode */
698
699 /** List of atom words. Default: "null" */
700 atoms?: unknown | undefined;
701 /** List of meta hooks. Default: ["`", "$"] */
702 hooks?: unknown | undefined;
703 /** Whether multi-line strings are accepted. Default: false */
704 multiLineStrings?: boolean | undefined;
705
706 /** Below options are supported in XML mode */
707
708 /**
709 * This switches the mode to parse HTML instead of XML. This means attributes do not have to be quoted,
710 * and some elements (such as br) do not require a closing tag.
711 */
712 htmlMode?: boolean | undefined;
713 /**
714 * Controls whether the mode checks that close tags match the corresponding opening tag,
715 * and highlights mismatches as errors. Defaults to true.
716 */
717 matchClosing?: boolean | undefined;
718 /** Setting this to true will force the opening tag of CDATA blocks to not be indented. */
719 alignCDATA?: boolean | undefined;
720 }
721
722 type ModeSpec<T> = {
723 [P in keyof T]: T[P];
724 } & { name: string };
725
726 interface SelectionOptions {
727 /**
728 * Determines whether the selection head should be scrolled into view. Defaults to true.
729 */
730 scroll?: boolean | undefined;
731
732 /**
733 * Determines whether the selection history event may be merged with the previous one.
734 * When an origin starts with the character +, and the last recorded selection had the same origin
735 * and was similar (close in time, both collapsed or both non-collapsed), the new one will replace
736 * the old one. When it starts with *, it will always replace the previous event (if that had the same
737 * origin). Built-in motion uses the "+move" origin. User input uses the "+input" origin.
738 */
739 origin?: string | undefined;
740
741 /**
742 * Determine the direction into which the selection endpoints should be adjusted when they fall inside
743 * an atomic range. Can be either -1 (backward) or 1 (forward). When not given, the bias will be based
744 * on the relative position of the old selection—the editor will try to move further away from that,
745 * to prevent getting stuck.
746 */
747 bias?: number | undefined;
748 }
749
750 interface DocConstructor {
751 new (text: string, mode?: string | ModeSpec<ModeSpecOptions>, firstLineNumber?: number, lineSep?: string): Doc;
752 (text: string, mode?: string | ModeSpec<ModeSpecOptions>, firstLineNumber?: number, lineSep?: string): Doc;
753 }
754
755 interface DocOrEditor {
756 /** Get the mode option */
757 modeOption: string | ModeSpec<ModeSpecOptions>;
758
759 /** Get the current editor content. You can pass it an optional argument to specify the string to be used to separate lines (defaults to "\n"). */
760 getValue(seperator?: string): string;
761
762 /** Set the editor content. */
763 setValue(content: string): void;
764
765 /**
766 * Get the text between the given points in the editor, which should be {line, ch} objects.
767 * An optional third argument can be given to indicate the line separator string to use (defaults to "\n").
768 */
769 getRange(from: Position, to: Position, seperator?: string): string;
770
771 /**
772 * Replace the part of the document between from and to with the given string.
773 * from and to must be {line, ch} objects. to can be left off to simply insert the string at position from.
774 */
775 replaceRange(
776 replacement: string | string[],
777 from: Position,
778 to?: Position,
779 origin?: string,
780 ): void;
781
782 /** Get the content of line n. */
783 getLine(n: number): string;
784
785 /** Set the content of line n. */
786 setLine(n: number, text: string): void;
787
788 /** Remove the given line from the document. */
789 removeLine(n: number): void;
790
791 /** Get the number of lines in the editor. */
792 lineCount(): number;
793
794 /**
795 * Get the first line of the editor. This will usually be zero but for linked sub-views,
796 * or documents instantiated with a non-zero first line, it might return other values.
797 */
798 firstLine(): number;
799
800 /** Get the last line of the editor. This will usually be lineCount() - 1, but for linked sub-views, it might return other values. */
801 lastLine(): number;
802
803 /** Fetches the line handle for the given line number. */
804 getLineHandle(num: number): LineHandle;
805
806 /** Given a line handle, returns the current position of that line (or null when it is no longer in the document). */
807 getLineNumber(handle: LineHandle): number | null;
808
809 /**
810 * Iterate over the whole document, and call f for each line, passing the line handle.
811 * This is a faster way to visit a range of line handlers than calling getLineHandle for each of them.
812 * Note that line handles have a text property containing the line's content (as a string).
813 */
814 eachLine(f: (line: LineHandle) => void): void;
815
816 /**
817 * Iterate over the range from start up to (not including) end, and call f for each line, passing the line handle.
818 * This is a faster way to visit a range of line handlers than calling getLineHandle for each of them.
819 * Note that line handles have a text property containing the line's content (as a string).
820 */
821 eachLine(start: number, end: number, f: (line: LineHandle) => void): void;
822
823 /**
824 * Set the editor content as 'clean', a flag that it will retain until it is edited, and which will be set again
825 * when such an edit is undone again. Useful to track whether the content needs to be saved. This function is deprecated
826 * in favor of changeGeneration, which allows multiple subsystems to track different notions of cleanness without interfering.
827 */
828 markClean(): void;
829
830 /**
831 * Returns a number that can later be passed to isClean to test whether any edits were made (and not undone) in the
832 * meantime. If closeEvent is true, the current history event will be ‘closed’, meaning it can't be combined with further
833 * changes (rapid typing or deleting events are typically combined).
834 */
835 changeGeneration(closeEvent?: boolean): number;
836
837 /**
838 * Returns whether the document is currently clean — not modified since initialization or the last call to markClean if
839 * no argument is passed, or since the matching call to changeGeneration if a generation value is given.
840 */
841 isClean(generation?: number): boolean;
842
843 /** Get the currently selected code. */
844 getSelection(): string;
845
846 /** Returns an array containing a string for each selection, representing the content of the selections. */
847 getSelections(lineSep?: string): string[];
848
849 /**
850 * Replace the selection with the given string. By default, the new selection will span the inserted text.
851 * The optional collapse argument can be used to change this -- passing "start" or "end" will collapse the selection to the start or end of the inserted text.
852 */
853 replaceSelection(replacement: string, collapse?: string): void;
854
855 /**
856 * Replaces the content of the selections with the strings in the array.
857 * The length of the given array should be the same as the number of active selections.
858 * The collapse argument works the same as in replaceSelection.
859 */
860 replaceSelections(replacements: string[], collapse?: string): void;
861
862 /**
863 * start is a an optional string indicating which end of the selection to return.
864 * It may be "from", "to", "head" (the side of the selection that moves when you press shift+arrow),
865 * or "anchor" (the fixed side of the selection).Omitting the argument is the same as passing "head". A {line, ch} object will be returned.
866 */
867 getCursor(start?: string): Position;
868
869 /**
870 * Retrieves a list of all current selections. These will always be sorted, and never overlap (overlapping selections are merged).
871 * Each object in the array contains anchor and head properties referring to {line, ch} objects.
872 */
873 listSelections(): Range[];
874
875 /** Return true if any text is selected. */
876 somethingSelected(): boolean;
877
878 /**
879 * Set the cursor position. You can either pass a single {line, ch} object, or the line and the character as two separate parameters.
880 * Will replace all selections with a single, empty selection at the given position.
881 * The supported options are the same as for setSelection
882 */
883 setCursor(
884 pos: Position | number,
885 ch?: number,
886 options?: { bias?: number | undefined; origin?: string | undefined; scroll?: boolean | undefined },
887 ): void;
888
889 /** Set a single selection range. anchor and head should be {line, ch} objects. head defaults to anchor when not given. */
890 setSelection(
891 anchor: Position,
892 head?: Position,
893 options?: { bias?: number | undefined; origin?: string | undefined; scroll?: boolean | undefined },
894 ): void;
895
896 /**
897 * Sets a new set of selections. There must be at least one selection in the given array. When primary is a
898 * number, it determines which selection is the primary one. When it is not given, the primary index is taken from
899 * the previous selection, or set to the last range if the previous selection had less ranges than the new one.
900 * Supports the same options as setSelection.
901 */
902 setSelections(
903 ranges: Array<{ anchor: Position; head: Position }>,
904 primary?: number,
905 options?: SelectionOptions,
906 ): void;
907
908 /**
909 * Adds a new selection to the existing set of selections, and makes it the primary selection.
910 */
911 addSelection(anchor: Position, head?: Position): void;
912
913 /**
914 * Similar to setSelection, but will, if shift is held or the extending flag is set,
915 * move the head of the selection while leaving the anchor at its current place.
916 * to is optional, and can be passed to ensure a region (for example a word or paragraph) will end up selected
917 * (in addition to whatever lies between that region and the current anchor). When multiple selections
918 * are present, all but the primary selection will be dropped by this method. Supports the same options
919 * as setSelection.
920 */
921 extendSelection(from: Position, to?: Position, options?: SelectionOptions): void;
922
923 /**
924 * An equivalent of extendSelection that acts on all selections at once.
925 */
926 extendSelections(heads: Position[], options?: SelectionOptions): void;
927
928 /**
929 * Applies the given function to all existing selections, and calls extendSelections on the result.
930 */
931 extendSelectionsBy(f: (range: Range) => Position): void;
932
933 /**
934 * Sets or clears the 'extending' flag , which acts similar to the shift key,
935 * in that it will cause cursor movement and calls to extendSelection to leave the selection anchor in place.
936 */
937 setExtending(value: boolean): void;
938
939 /**
940 * Get the value of the 'extending' flag.
941 */
942 getExtending(): boolean;
943
944 /** Create a new document that's linked to the target document. Linked documents will stay in sync (changes to one are also applied to the other) until unlinked. */
945 linkedDoc(options: {
946 /**
947 * When turned on, the linked copy will share an undo history with the original.
948 * Thus, something done in one of the two can be undone in the other, and vice versa.
949 */
950 sharedHist?: boolean | undefined;
951 from?: number | undefined;
952 /**
953 * Can be given to make the new document a subview of the original. Subviews only show a given range of lines.
954 * Note that line coordinates inside the subview will be consistent with those of the parent,
955 * so that for example a subview starting at line 10 will refer to its first line as line 10, not 0.
956 */
957 to?: number | undefined;
958 /** By default, the new document inherits the mode of the parent. This option can be set to a mode spec to give it a different mode. */
959 mode?: string | ModeSpec<ModeSpecOptions> | undefined;
960 }): Doc;
961
962 /**
963 * Break the link between two documents. After calling this , changes will no longer propagate between the documents,
964 * and, if they had a shared history, the history will become separate.
965 */
966 unlinkDoc(doc: Doc): void;
967
968 /**
969 * Will call the given function for all documents linked to the target document. It will be passed two arguments,
970 * the linked document and a boolean indicating whether that document shares history with the target.
971 */
972 iterLinkedDocs(fn: (doc: Doc, sharedHist: boolean) => void): void;
973
974 /** Undo one edit (if any undo events are stored). */
975 undo(): void;
976
977 /** Redo one undone edit. */
978 redo(): void;
979
980 /**
981 * Undo one edit or selection change.
982 */
983 undoSelection(): void;
984
985 /**
986 * Redo one undone edit or selection change.
987 */
988 redoSelection(): void;
989
990 /** Returns an object with {undo, redo } properties , both of which hold integers , indicating the amount of stored undo and redo operations. */
991 historySize(): { undo: number; redo: number };
992
993 /** Clears the editor's undo history. */
994 clearHistory(): void;
995
996 /** Get a (JSON - serializeable) representation of the undo history. */
997 getHistory(): any;
998
999 /**
1000 * Replace the editor's undo history with the one provided, which must be a value as returned by getHistory.
1001 * Note that this will have entirely undefined results if the editor content isn't also the same as it was when getHistory was called.
1002 */
1003 setHistory(history: any): void;
1004
1005 /** Can be used to mark a range of text with a specific CSS class name. from and to should be { line , ch } objects. */
1006 markText(
1007 from: Position,
1008 to: Position,
1009 options?: TextMarkerOptions,
1010 ): TextMarker<MarkerRange>;
1011
1012 /**
1013 * Inserts a bookmark, a handle that follows the text around it as it is being edited, at the given position.
1014 * A bookmark has two methods find() and clear(). The first returns the current position of the bookmark, if it is still in the document,
1015 * and the second explicitly removes the bookmark.
1016 */
1017 setBookmark(
1018 pos: Position,
1019 options?: {
1020 /** Can be used to display a DOM node at the current location of the bookmark (analogous to the replacedWith option to markText). */
1021 widget?: HTMLElement | undefined;
1022
1023 /**
1024 * By default, text typed when the cursor is on top of the bookmark will end up to the right of the bookmark.
1025 * Set this option to true to make it go to the left instead.
1026 */
1027 insertLeft?: boolean | undefined;
1028
1029 /**
1030 * When the target document is linked to other documents, you can set shared to true to make the marker appear in all documents.
1031 * By default, a marker appears only in its target document.
1032 */
1033 shared?: boolean | undefined;
1034
1035 /** As with markText, this determines whether mouse events on the widget inserted for this bookmark are handled by CodeMirror. The default is false. */
1036 handleMouseEvents?: boolean | undefined;
1037 },
1038 ): TextMarker<Position>;
1039
1040 /** Returns an array of all the bookmarks and marked ranges found between the given positions. */
1041 findMarks(from: Position, to: Position): TextMarker[];
1042
1043 /** Returns an array of all the bookmarks and marked ranges present at the given position. */
1044 findMarksAt(pos: Position): TextMarker[];
1045
1046 /** Returns an array containing all marked ranges in the document. */
1047 getAllMarks(): TextMarker[];
1048
1049 /**
1050 * Adds a line widget, an element shown below a line, spanning the whole of the editor's width, and moving the lines below it downwards.
1051 * line should be either an integer or a line handle, and node should be a DOM node, which will be displayed below the given line.
1052 * options, when given, should be an object that configures the behavior of the widget.
1053 * Note that the widget node will become a descendant of nodes with CodeMirror-specific CSS classes, and those classes might in some cases affect it.
1054 */
1055 addLineWidget(line: any, node: HTMLElement, options?: LineWidgetOptions): LineWidget;
1056
1057 /** Remove the line widget */
1058 removeLineWidget(widget: LineWidget): void;
1059
1060 /**
1061 * Gets the mode object for the editor. Note that this is distinct from getOption("mode"), which gives you the mode specification,
1062 * rather than the resolved, instantiated mode object.
1063 */
1064 getMode(): Mode<unknown>;
1065
1066 /** Returns the preferred line separator string for this document, as per the option by the same name. When that option is null, the string "\n" is returned. */
1067 lineSeparator(): string;
1068
1069 /**
1070 * Calculates and returns a { line , ch } object for a zero-based index whose value is relative to the start of the editor's text.
1071 * If the index is out of range of the text then the returned object is clipped to start or end of the text respectively.
1072 */
1073 posFromIndex(index: number): Position;
1074
1075 /** The reverse of posFromIndex. */
1076 indexFromPos(object: Position): number;
1077
1078 /** Expose the state object, so that the Doc.state.completionActive property is reachable */
1079 state: any;
1080 }
1081
1082 interface Doc extends DocOrEditor {
1083 /** Retrieve the editor associated with a document. May return null. */
1084 getEditor(): Editor | null;
1085
1086 /** Create an identical copy of the given doc. When copyHistory is true , the history will also be copied. */
1087 copy(copyHistory: boolean): Doc;
1088
1089 on<T extends keyof DocEventMap>(eventName: T, handler: DocEventMap[T]): void;
1090 off<T extends keyof DocEventMap>(eventName: T, handler: DocEventMap[T]): void;
1091 }
1092
1093 interface LineHandle {
1094 text: string;
1095 on<T extends keyof LineHandleEventMap>(eventName: T, handler: LineHandleEventMap[T]): void;
1096 off<T extends keyof LineHandleEventMap>(leventName: T, handler: LineHandleEventMap[T]): void;
1097 }
1098
1099 interface ScrollInfo {
1100 left: number;
1101 top: number;
1102 width: number;
1103 height: number;
1104 clientWidth: number;
1105 clientHeight: number;
1106 }
1107
1108 interface MarkerRange {
1109 from: Position;
1110 to: Position;
1111 }
1112
1113 interface TextMarker<T = MarkerRange | Position> extends Partial<TextMarkerOptions> {
1114 /** Remove the mark. */
1115 clear(): void;
1116
1117 /**
1118 * Returns a {from, to} object (both holding document positions), indicating the current position of the marked range,
1119 * or undefined if the marker is no longer in the document.
1120 */
1121 find(): T | undefined;
1122
1123 /** Called when you've done something that might change the size of the marker and want to cheaply update the display */
1124 changed(): void;
1125
1126 on<T extends keyof TextMarkerEventMap>(eventName: T, handler: TextMarkerEventMap[T]): void;
1127 off<T extends keyof TextMarkerEventMap>(eventName: T, handler: TextMarkerEventMap[T]): void;
1128 }
1129
1130 interface LineWidget {
1131 /** Removes the widget. */
1132 clear(): void;
1133
1134 /**
1135 * Call this if you made some change to the widget's DOM node that might affect its height.
1136 * It'll force CodeMirror to update the height of the line that contains the widget.
1137 */
1138 changed(): void;
1139
1140 on<T extends keyof LineWidgetEventMap>(eventName: T, handler: LineWidgetEventMap[T]): void;
1141 off<T extends keyof LineWidgetEventMap>(eventName: T, handler: LineWidgetEventMap[T]): void;
1142 }
1143
1144 interface LineWidgetOptions {
1145 /** Whether the widget should cover the gutter. */
1146 coverGutter?: boolean | undefined;
1147 /** Whether the widget should stay fixed in the face of horizontal scrolling. */
1148 noHScroll?: boolean | undefined;
1149 /** Causes the widget to be placed above instead of below the text of the line. */
1150 above?: boolean | undefined;
1151 /** When true, will cause the widget to be rendered even if the line it is associated with is hidden. */
1152 showIfHidden?: boolean | undefined;
1153 /**
1154 * Determines whether the editor will capture mouse and drag events occurring in this widget.
1155 * Default is false—the events will be left alone for the default browser handler, or specific handlers on the widget, to capture.
1156 */
1157 handleMouseEvents?: boolean | undefined;
1158 /**
1159 * By default, the widget is added below other widgets for the line.
1160 * This option can be used to place it at a different position (zero for the top, N to put it after the Nth other widget).
1161 * Note that this only has effect once, when the widget is created.
1162 */
1163 insertAt?: number | undefined;
1164 /** Add an extra CSS class name to the wrapper element created for the widget. */
1165 className?: string | undefined;
1166 }
1167
1168 interface EditorChange {
1169 /** Position (in the pre-change coordinate system) where the change started. */
1170 from: Position;
1171 /** Position (in the pre-change coordinate system) where the change ended. */
1172 to: Position;
1173 /** Array of strings representing the text that replaced the changed range (split by line). */
1174 text: string[];
1175 /** Text that used to be between from and to, which is overwritten by this change. */
1176 removed?: string[] | undefined;
1177 /** String representing the origin of the change event and whether it can be merged with history */
1178 origin?: string | undefined;
1179 }
1180
1181 interface EditorChangeCancellable extends EditorChange {
1182 /**
1183 * may be used to modify the change. All three arguments to update are optional, and can be left off to leave the existing value for that field intact.
1184 * If the change came from undo/redo, `update` is undefined and the change cannot be modified.
1185 */
1186 update?(from?: Position, to?: Position, text?: string[]): void;
1187
1188 cancel(): void;
1189 }
1190
1191 interface PositionConstructor {
1192 new (line: number, ch?: number, sticky?: string): Position;
1193 (line: number, ch?: number, sticky?: string): Position;
1194 }
1195
1196 interface EditorSelectionChange {
1197 ranges: Range[];
1198 update(ranges: Range[]): void;
1199 origin?: string | undefined;
1200 }
1201
1202 interface Range {
1203 anchor: Position;
1204 head: Position;
1205 from(): Position;
1206 to(): Position;
1207 empty(): boolean;
1208 }
1209
1210 interface Position {
1211 ch: number;
1212 line: number;
1213 sticky?: string | undefined;
1214 }
1215
1216 interface ScrollbarMeasure {
1217 clientHeight: number;
1218 viewHeight: number;
1219 scrollWidth: number;
1220 viewWidth: number;
1221 barLeft: number;
1222 docHeight: number;
1223 scrollHeight: number;
1224 nativeBarWidth: number;
1225 gutterWidth: number;
1226 }
1227
1228 interface ScrollbarModel {
1229 update(measure: ScrollbarMeasure): { bottom: number, right: number };
1230 clear(): void;
1231 setScrollLeft(pos: number): void;
1232 setScrollTop(pos: number): void;
1233 }
1234
1235 interface ScrollbarModelConstructor {
1236 new(place: (node: Element) => void, scroll: (pos: number, axis: 'horizontal' | 'vertical') => void): ScrollbarModel;
1237 }
1238
1239 interface ScrollbarModels {
1240 native: ScrollbarModelConstructor;
1241 null: ScrollbarModelConstructor;
1242 }
1243
1244 const scrollbarModel: ScrollbarModels;
1245
1246 type InputStyle = 'textarea' | 'contenteditable';
1247
1248 interface EditorConfiguration {
1249 /** The starting value of the editor. Can be a string, or a document object. */
1250 value?: string | Doc | undefined;
1251
1252 /**
1253 * string|object. The mode to use. When not given, this will default to the first mode that was loaded.
1254 * It may be a string, which either simply names the mode or is a MIME type associated with the mode.
1255 * Alternatively, it may be an object containing configuration options for the mode,
1256 * with a name property that names the mode (for example {name: "javascript", json: true}).
1257 */
1258 mode?: string | ModeSpec<ModeSpecOptions> | undefined;
1259
1260 /**
1261 * Explicitly set the line separator for the editor. By default (value null), the document will be split on CRLFs as well
1262 * as lone CRs and LFs, and a single LF will be used as line separator in all output (such as getValue). When a specific
1263 * string is given, lines will only be split on that string, and output will, by default, use that same separator.
1264 */
1265 lineSeparator?: string | null | undefined;
1266
1267 /**
1268 * The theme to style the editor with. You must make sure the CSS file defining the corresponding .cm-s-[name] styles is loaded.
1269 * The default is "default".
1270 */
1271 theme?: string | undefined;
1272
1273 /** How many spaces a block (whatever that means in the edited language) should be indented. The default is 2. */
1274 indentUnit?: number | undefined;
1275
1276 /** Whether to use the context-sensitive indentation that the mode provides (or just indent the same as the line before). Defaults to true. */
1277 smartIndent?: boolean | undefined;
1278
1279 /** The width of a tab character. Defaults to 4. */
1280 tabSize?: number | undefined;
1281
1282 /** Whether, when indenting, the first N*tabSize spaces should be replaced by N tabs. Default is false. */
1283 indentWithTabs?: boolean | undefined;
1284
1285 /**
1286 * Configures whether the editor should re-indent the current line when a character is typed
1287 * that might change its proper indentation (only works if the mode supports indentation). Default is true.
1288 */
1289 electricChars?: boolean | undefined;
1290
1291 /**
1292 * A regular expression used to determine which characters should be replaced by a special placeholder. Mostly useful for non-printing
1293 * special characters. The default is /[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b-\u200f\u2028\u2029\ufeff\ufff9-\ufffc]/.
1294 */
1295 specialChars?: RegExp | undefined;
1296
1297 /**
1298 * A function that, given a special character identified by the specialChars option, produces a DOM node that is used to
1299 * represent the character. By default, a red dot (•) is shown, with a title tooltip to indicate the character code.
1300 */
1301 specialCharPlaceholder?: ((char: string) => HTMLElement) | undefined;
1302
1303 /**
1304 * Flips overall layout and selects base paragraph direction to be left-to-right or right-to-left. Default is "ltr". CodeMirror
1305 * applies the Unicode Bidirectional Algorithm to each line, but does not autodetect base direction — it's set to the editor
1306 * direction for all lines. The resulting order is sometimes wrong when base direction doesn't match user intent (for example,
1307 * leading and trailing punctuation jumps to the wrong side of the line). Therefore, it's helpful for multilingual input to let
1308 * users toggle this option.
1309 */
1310 direction?: "ltr" | "rtl" | undefined;
1311
1312 /**
1313 * Determines whether horizontal cursor movement through right-to-left (Arabic, Hebrew) text
1314 * is visual (pressing the left arrow moves the cursor left)
1315 * or logical (pressing the left arrow moves to the next lower index in the string, which is visually right in right-to-left text).
1316 * The default is false on Windows, and true on other platforms.
1317 */
1318 rtlMoveVisually?: boolean | undefined;
1319
1320 /**
1321 * Configures the keymap to use. The default is "default", which is the only keymap defined in codemirror.js itself.
1322 * Extra keymaps are found in the keymap directory. See the section on keymaps for more information.
1323 */
1324 keyMap?: string | undefined;
1325
1326 /** Can be used to specify extra keybindings for the editor, alongside the ones defined by keyMap. Should be either null, or a valid keymap value. */
1327 extraKeys?: string | KeyMap | undefined;
1328
1329 /** Allows you to configure the behavior of mouse selection and dragging. The function is called when the left mouse button is pressed. */
1330 configureMouse?: ((
1331 cm: Editor,
1332 repeat: 'single' | 'double' | 'triple',
1333 event: Event,
1334 ) => MouseSelectionConfiguration) | undefined;
1335
1336 /** Whether CodeMirror should scroll or wrap for long lines. Defaults to false (scroll). */
1337 lineWrapping?: boolean | undefined;
1338
1339 /** Whether to show line numbers to the left of the editor. */
1340 lineNumbers?: boolean | undefined;
1341
1342 /** At which number to start counting lines. Default is 1. */
1343 firstLineNumber?: number | undefined;
1344
1345 /** A function used to format line numbers. The function is passed the line number, and should return a string that will be shown in the gutter. */
1346 lineNumberFormatter?: ((line: number) => string) | undefined;
1347
1348 /**
1349 * Can be used to add extra gutters (beyond or instead of the line number gutter).
1350 * Should be an array of CSS class names, each of which defines a width (and optionally a background),
1351 * and which will be used to draw the background of the gutters.
1352 * May include the CodeMirror-linenumbers class, in order to explicitly set the position of the line number gutter
1353 * (it will default to be to the right of all other gutters). These class names are the keys passed to setGutterMarker.
1354 */
1355 gutters?: Array<string | { className: string; style?: string | undefined }> | undefined;
1356
1357 /**
1358 * Determines whether the gutter scrolls along with the content horizontally (false)
1359 * or whether it stays fixed during horizontal scrolling (true, the default).
1360 */
1361 fixedGutter?: boolean | undefined;
1362
1363 /**
1364 * Chooses a scrollbar implementation. The default is "native", showing native scrollbars. The core library also
1365 * provides the "null" style, which completely hides the scrollbars. Addons can implement additional scrollbar models.
1366 */
1367 scrollbarStyle?: keyof ScrollbarModels | undefined;
1368
1369 /**
1370 * When fixedGutter is on, and there is a horizontal scrollbar, by default the gutter will be visible to the left of this scrollbar.
1371 * If this option is set to true, it will be covered by an element with class CodeMirror-gutter-filler.
1372 */
1373 coverGutterNextToScrollbar?: boolean | undefined;
1374
1375 /**
1376 * Selects the way CodeMirror handles input and focus.
1377 * The core library defines the "textarea" and "contenteditable" input models.
1378 * On mobile browsers, the default is "contenteditable". On desktop browsers, the default is "textarea".
1379 * Support for IME and screen readers is better in the "contenteditable" model.
1380 */
1381 inputStyle?: InputStyle | undefined;
1382
1383 /** boolean|string. This disables editing of the editor content by the user. If the special value "nocursor" is given (instead of simply true), focusing of the editor is also disallowed. */
1384 readOnly?: boolean | 'nocursor' | undefined;
1385
1386 /** This label is read by the screenreaders when CodeMirror text area is focused. This is helpful for accessibility. */
1387 screenReaderLabel?: string | undefined;
1388
1389 /** Whether the cursor should be drawn when a selection is active. Defaults to false. */
1390 showCursorWhenSelecting?: boolean | undefined;
1391
1392 /** When enabled, which is the default, doing copy or cut when there is no selection will copy or cut the whole lines that have cursors on them. */
1393 lineWiseCopyCut?: boolean | undefined;
1394
1395 /**
1396 * When pasting something from an external source (not from the editor itself), if the number of lines matches the number of selection,
1397 * CodeMirror will by default insert one line per selection. You can set this to false to disable that behavior.
1398 */
1399 pasteLinesPerSelection?: boolean | undefined;
1400
1401 /** Determines whether multiple selections are joined as soon as they touch (the default) or only when they overlap (true). */
1402 selectionsMayTouch?: boolean | undefined;
1403
1404 /** The maximum number of undo levels that the editor stores. Defaults to 40. */
1405 undoDepth?: number | undefined;
1406
1407 /** The period of inactivity (in milliseconds) that will cause a new history event to be started when typing or deleting. Defaults to 500. */
1408 historyEventDelay?: number | undefined;
1409
1410 /** The tab index to assign to the editor. If not given, no tab index will be assigned. */
1411 tabindex?: number | undefined;
1412
1413 /**
1414 * Can be used to make CodeMirror focus itself on initialization. Defaults to off.
1415 * When fromTextArea is used, and no explicit value is given for this option, it will be set to true when either the source textarea is focused,
1416 * or it has an autofocus attribute and no other element is focused.
1417 */
1418 autofocus?: boolean | undefined;
1419
1420 /**
1421 * Some addons run user-visible strings (such as labels in the interface) through the phrase method to allow for translation.
1422 * This option determines the return value of that method. When it is null or an object that doesn't have a property named by
1423 * the input string, that string is returned. Otherwise, the value of the property corresponding to that string is returned.
1424 */
1425 phrases?: {[s: string]: unknown} | undefined;
1426
1427 /** Controls whether drag-and - drop is enabled. On by default. */
1428 dragDrop?: boolean | undefined;
1429
1430 /**
1431 * When set (default is null) only files whose type is in the array can be dropped into the editor.
1432 * The strings should be MIME types, and will be checked against the type of the File object as reported by the browser.
1433 */
1434 allowDropFileTypes?: string[] | null | undefined;
1435
1436 /**
1437 * When given , this will be called when the editor is handling a dragenter , dragover , or drop event.
1438 * It will be passed the editor instance and the event object as arguments.
1439 * The callback can choose to handle the event itself , in which case it should return true to indicate that CodeMirror should not do anything further.
1440 */
1441 onDragEvent?: ((instance: Editor, event: DragEvent) => boolean) | undefined;
1442
1443 /**
1444 * This provides a rather low-level hook into CodeMirror's key handling.
1445 * If provided, this function will be called on every keydown, keyup, and keypress event that CodeMirror captures.
1446 * It will be passed two arguments, the editor instance and the key event.
1447 * This key event is pretty much the raw key event, except that a stop() method is always added to it.
1448 * You could feed it to, for example, jQuery.Event to further normalize it.
1449 * This function can inspect the key event, and handle it if it wants to.
1450 * It may return true to tell CodeMirror to ignore the event.
1451 * Be wary that, on some browsers, stopping a keydown does not stop the keypress from firing, whereas on others it does.
1452 * If you respond to an event, you should probably inspect its type property and only do something when it is keydown
1453 * (or keypress for actions that need character data).
1454 */
1455 onKeyEvent?: ((instance: Editor, event: KeyboardEvent) => boolean) | undefined;
1456
1457 /** Half - period in milliseconds used for cursor blinking. The default blink rate is 530ms. */
1458 cursorBlinkRate?: number | undefined;
1459
1460 /**
1461 * How much extra space to always keep above and below the cursor when
1462 * approaching the top or bottom of the visible view in a scrollable document. Default is 0.
1463 */
1464 cursorScrollMargin?: number | undefined;
1465
1466 /**
1467 * Determines the height of the cursor. Default is 1 , meaning it spans the whole height of the line.
1468 * For some fonts (and by some tastes) a smaller height (for example 0.85),
1469 * which causes the cursor to not reach all the way to the bottom of the line, looks better
1470 */
1471 cursorHeight?: number | undefined;
1472
1473 /**
1474 * Controls whether, when the context menu is opened with a click outside of the current selection,
1475 * the cursor is moved to the point of the click. Defaults to true.
1476 */
1477 resetSelectionOnContextMenu?: boolean | undefined;
1478
1479 /**
1480 * Highlighting is done by a pseudo background thread that will work for workTime milliseconds,
1481 * and then use timeout to sleep for workDelay milliseconds.
1482 * The defaults are 200 and 300, you can change these options to make the highlighting more or less aggressive.
1483 */
1484 workTime?: number | undefined;
1485
1486 /** See workTime. */
1487 workDelay?: number | undefined;
1488
1489 /**
1490 * Indicates how quickly CodeMirror should poll its input textarea for changes(when focused).
1491 * Most input is captured by events, but some things, like IME input on some browsers, don't generate events that allow CodeMirror to properly detect it.
1492 * Thus, it polls. Default is 100 milliseconds.
1493 */
1494 pollInterval?: number | undefined;
1495
1496 /**
1497 * By default, CodeMirror will combine adjacent tokens into a single span if they have the same class.
1498 * This will result in a simpler DOM tree, and thus perform better. With some kinds of styling(such as rounded corners),
1499 * this will change the way the document looks. You can set this option to false to disable this behavior.
1500 */
1501 flattenSpans?: boolean | undefined;
1502
1503 /**
1504 * When enabled (off by default), an extra CSS class will be added to each token, indicating the (inner) mode that produced it, prefixed with "cm-m-".
1505 * For example, tokens from the XML mode will get the cm-m-xml class.
1506 */
1507 addModeClass?: boolean | undefined;
1508
1509 /**
1510 * When highlighting long lines, in order to stay responsive, the editor will give up and simply style
1511 * the rest of the line as plain text when it reaches a certain position. The default is 10000.
1512 * You can set this to Infinity to turn off this behavior.
1513 */
1514 maxHighlightLength?: number | undefined;
1515
1516 /**
1517 * Specifies the amount of lines that are rendered above and below the part of the document that's currently scrolled into view.
1518 * This affects the amount of updates needed when scrolling, and the amount of work that such an update does.
1519 * You should usually leave it at its default, 10. Can be set to Infinity to make sure the whole document is always rendered,
1520 * and thus the browser's text search works on it. This will have bad effects on performance of big documents.
1521 */
1522 viewportMargin?: number | undefined;
1523
1524 /** Specifies whether or not spellcheck will be enabled on the input. */
1525 spellcheck?: boolean | undefined;
1526
1527 /** Specifies whether or not autocorrect will be enabled on the input. */
1528 autocorrect?: boolean | undefined;
1529
1530 /** Specifies whether or not autocapitalization will be enabled on the input. */
1531 autocapitalize?: boolean | undefined;
1532 }
1533
1534 interface TextMarkerOptions {
1535 /** Assigns a CSS class to the marked stretch of text. */
1536 className?: string | undefined;
1537
1538 /** Determines whether text inserted on the left of the marker will end up inside or outside of it. */
1539 inclusiveLeft?: boolean | undefined;
1540
1541 /** Like inclusiveLeft, but for the right side. */
1542 inclusiveRight?: boolean | undefined;
1543
1544 /** For atomic ranges, determines whether the cursor is allowed to be placed directly to the left of the range. Has no effect on non-atomic ranges. */
1545 selectLeft?: boolean | undefined;
1546
1547 /** Like selectLeft, but for the right side. */
1548 selectRight?: boolean | undefined;
1549
1550 /**
1551 * Atomic ranges act as a single unit when cursor movement is concerned — i.e. it is impossible to place the cursor inside of them.
1552 * You can control whether the cursor is allowed to be placed directly before or after them using selectLeft or selectRight.
1553 * If selectLeft (or right) is not provided, then inclusiveLeft (or right) will control this behavior.
1554 */
1555 atomic?: boolean | undefined;
1556
1557 /** Collapsed ranges do not show up in the display. Setting a range to be collapsed will automatically make it atomic. */
1558 collapsed?: boolean | undefined;
1559
1560 /**
1561 * When enabled, will cause the mark to clear itself whenever the cursor enters its range.
1562 * This is mostly useful for text - replacement widgets that need to 'snap open' when the user tries to edit them.
1563 * The "clear" event fired on the range handle can be used to be notified when this happens.
1564 */
1565 clearOnEnter?: boolean | undefined;
1566
1567 /** Determines whether the mark is automatically cleared when it becomes empty. Default is true. */
1568 clearWhenEmpty?: boolean | undefined;
1569
1570 /**
1571 * Use a given node to display this range. Implies both collapsed and atomic.
1572 * The given DOM node must be an inline element (as opposed to a block element).
1573 */
1574 replacedWith?: HTMLElement | undefined;
1575
1576 /**
1577 * When replacedWith is given, this determines whether the editor will
1578 * capture mouse and drag events occurring in this widget. Default is
1579 * false—the events will be left alone for the default browser handler,
1580 * or specific handlers on the widget, to capture.
1581 */
1582 handleMouseEvents?: boolean | undefined;
1583
1584 /**
1585 * A read-only span can, as long as it is not cleared, not be modified except by calling setValue to reset the whole document.
1586 * Note: adding a read-only span currently clears the undo history of the editor,
1587 * because existing undo events being partially nullified by read - only spans would corrupt the history (in the current implementation).
1588 */
1589 readOnly?: boolean | undefined;
1590
1591 /** When set to true (default is false), adding this marker will create an event in the undo history that can be individually undone (clearing the marker). */
1592 addToHistory?: boolean | undefined;
1593
1594 /** Can be used to specify an extra CSS class to be applied to the leftmost span that is part of the marker. */
1595 startStyle?: string | undefined;
1596
1597 /** Equivalent to startStyle, but for the rightmost span. */
1598 endStyle?: string | undefined;
1599
1600 /** A string of CSS to be applied to the covered text. For example "color: #fe3". */
1601 css?: string | undefined;
1602
1603 /** When given, will give the nodes created for this span a HTML title attribute with the given value. */
1604 title?: string | undefined;
1605
1606 /** When given, add the attributes in the given object to the elements created for the marked text. Adding class or style attributes this way is not supported. */
1607 attributes?: { [name: string]: string } | undefined;
1608
1609 /**
1610 * When the target document is linked to other documents, you can set shared to true to make the marker appear in all documents.
1611 * By default, a marker appears only in its target document.
1612 */
1613 shared?: boolean | undefined;
1614 }
1615
1616 class StringStream {
1617 constructor(text: string);
1618 lastColumnPos: number;
1619 lastColumnValue: number;
1620 lineStart: number;
1621
1622 /**
1623 * Current position in the string.
1624 */
1625 pos: number;
1626
1627 /**
1628 * Where the stream's position was when it was first passed to the token function.
1629 */
1630 start: number;
1631
1632 /**
1633 * The current line's content.
1634 */
1635 string: string;
1636
1637 /**
1638 * Number of spaces per tab character.
1639 */
1640 tabSize: number;
1641
1642 /**
1643 * Returns true only if the stream is at the end of the line.
1644 */
1645 eol(): boolean;
1646
1647 /**
1648 * Returns true only if the stream is at the start of the line.
1649 */
1650 sol(): boolean;
1651
1652 /**
1653 * Returns the next character in the stream without advancing it. Will return an null at the end of the line.
1654 */
1655 peek(): string | null;
1656
1657 /**
1658 * Returns the next character in the stream and advances it. Also returns null when no more characters are available.
1659 */
1660 next(): string | null;
1661
1662 /**
1663 * match can be a character, a regular expression, or a function that takes a character and returns a boolean.
1664 * If the next character in the stream 'matches' the given argument, it is consumed and returned.
1665 * Otherwise, undefined is returned.
1666 */
1667 eat(match: string | RegExp | ((char: string) => boolean)): string;
1668
1669 /**
1670 * Repeatedly calls eat with the given argument, until it fails. Returns true if any characters were eaten.
1671 */
1672 eatWhile(match: string | RegExp | ((char: string) => boolean)): boolean;
1673
1674 /**
1675 * Shortcut for eatWhile when matching white-space.
1676 */
1677 eatSpace(): boolean;
1678
1679 /**
1680 * Moves the position to the end of the line.
1681 */
1682 skipToEnd(): void;
1683
1684 /**
1685 * Skips to the next occurrence of the given character, if found on the current line (doesn't advance the stream if
1686 * the character does not occur on the line).
1687 *
1688 * Returns true if the character was found.
1689 */
1690 skipTo(ch: string): boolean;
1691
1692 /**
1693 * Act like a multi-character eat - if consume is true or not given - or a look-ahead that doesn't update the stream
1694 * position - if it is false. pattern can be either a string or a regular expression starting with ^. When it is a
1695 * string, caseFold can be set to true to make the match case-insensitive. When successfully matching a regular
1696 * expression, the returned value will be the array returned by match, in case you need to extract matched groups.
1697 */
1698 match(pattern: string, consume?: boolean, caseFold?: boolean): boolean;
1699 match(pattern: RegExp, consume?: boolean): string[];
1700
1701 /**
1702 * Backs up the stream n characters. Backing it up further than the start of the current token will cause things to
1703 * break, so be careful.
1704 */
1705 backUp(n: number): void;
1706
1707 /**
1708 * Returns the column (taking into account tabs) at which the current token starts.
1709 */
1710 column(): number;
1711
1712 /**
1713 * Tells you how far the current line has been indented, in spaces. Corrects for tab characters.
1714 */
1715 indentation(): number;
1716
1717 /**
1718 * Get the string between the start of the current token and the current stream position.
1719 */
1720 current(): string;
1721
1722 /**
1723 * Returns the content of the line n lines ahead in the stream without
1724 * advancing it. Will return undefined if not found.
1725 */
1726 lookAhead(n: number): string | undefined;
1727 }
1728
1729 /**
1730 * A Mode is, in the simplest case, a lexer (tokenizer) for your language — a function that takes a character stream as input,
1731 * advances it past a token, and returns a style for that token. More advanced modes can also handle indentation for the language.
1732 */
1733 interface Mode<T> {
1734 name?: string | undefined;
1735
1736 /**
1737 * This function should read one token from the stream it is given as an argument, optionally update its state,
1738 * and return a style string, or null for tokens that do not have to be styled. Multiple styles can be returned, separated by spaces.
1739 */
1740 token: (stream: StringStream, state: T) => string | null;
1741
1742 /**
1743 * A function that produces a state object to be used at the start of a document.
1744 */
1745 startState?: (() => T) | undefined;
1746 /**
1747 * For languages that have significant blank lines, you can define a blankLine(state) method on your mode that will get called
1748 * whenever a blank line is passed over, so that it can update the parser state.
1749 */
1750 blankLine?: ((state: T) => void) | undefined;
1751 /**
1752 * Given a state returns a safe copy of that state.
1753 */
1754 copyState?: ((state: T) => T) | undefined;
1755
1756 /**
1757 * Returns the number of spaces of indentation that should be used if a newline were added after the given state. Optionally
1758 * this can use the textAfter string (which is the text after the current position) or the line string, which is the whole
1759 * text of the line.
1760 */
1761 indent?: ((state: T, textAfter: string, line: string) => number) | undefined;
1762
1763 /** The four below strings are used for working with the commenting addon. */
1764 /**
1765 * String that starts a line comment.
1766 */
1767 lineComment?: string | undefined;
1768 /**
1769 * String that starts a block comment.
1770 */
1771 blockCommentStart?: string | undefined;
1772 /**
1773 * String that ends a block comment.
1774 */
1775 blockCommentEnd?: string | undefined;
1776 /**
1777 * String to put at the start of continued lines in a block comment.
1778 */
1779 blockCommentLead?: string | undefined;
1780
1781 /**
1782 * Trigger a reindent whenever one of the characters in the string is typed.
1783 */
1784 electricChars?: string | undefined;
1785 /**
1786 * Trigger a reindent whenever the regex matches the part of the line before the cursor.
1787 */
1788 electricinput?: RegExp | undefined;
1789 }
1790
1791 /**
1792 * A function that, given a CodeMirror configuration object and an optional mode configuration object, returns a mode object.
1793 */
1794 interface ModeFactory<T> {
1795 (config: EditorConfiguration, modeOptions?: any): Mode<T>;
1796 }
1797
1798 /**
1799 * id will be the id for the defined mode. Typically, you should use this second argument to defineMode as your module scope function
1800 * (modes should not leak anything into the global scope!), i.e. write your whole mode inside this function.
1801 */
1802 function defineMode(id: string, modefactory: ModeFactory<any>): void;
1803
1804 /**
1805 * The first argument is a configuration object as passed to the mode constructor function, and the second argument
1806 * is a mode specification as in the EditorConfiguration mode option.
1807 */
1808 function getMode(config: EditorConfiguration, mode: string | ModeSpec<ModeSpecOptions>): Mode<unknown>;
1809
1810 /**
1811 * Utility function from the overlay.js addon that allows modes to be combined. The mode given as the base argument takes care of
1812 * most of the normal mode functionality, but a second (typically simple) mode is used, which can override the style of text.
1813 * Both modes get to parse all of the text, but when both assign a non-null style to a piece of code, the overlay wins, unless
1814 * the combine argument was true and not overridden, or state.overlay.combineTokens was true, in which case the styles are combined.
1815 */
1816 function overlayMode(base: Mode<any>, overlay: Mode<any>, combine?: boolean): Mode<any>;
1817
1818 interface ModeMap {
1819 [modeName: string]: ModeFactory<any>;
1820 }
1821
1822 /**
1823 * Maps mode names to their constructors
1824 */
1825 const modes: ModeMap;
1826
1827 function defineMIME(mime: string, modeSpec: string | ModeSpec<ModeSpecOptions>): void;
1828
1829 interface MimeModeMap {
1830 [mimeName: string]: string | ModeSpec<ModeSpecOptions>;
1831 }
1832
1833 /**
1834 * Maps MIME types to mode specs.
1835 */
1836 const mimeModes: MimeModeMap;
1837
1838 interface CommandActions {
1839 /** Select the whole content of the editor. */
1840 selectAll(cm: Editor): void;
1841
1842 /** When multiple selections are present, this deselects all but the primary selection. */
1843 singleSelection(cm: Editor): void;
1844
1845 /** Emacs-style line killing. Deletes the part of the line after the cursor. If that consists only of whitespace, the newline at the end of the line is also deleted. */
1846 killLine(cm: Editor): void;
1847
1848 /** Deletes the whole line under the cursor, including newline at the end. */
1849 deleteLine(cm: Editor): void;
1850
1851 /** Delete the part of the line before the cursor. */
1852 delLineLeft(cm: Editor): void;
1853
1854 /** Delete the part of the line from the left side of the visual line the cursor is on to the cursor. */
1855 delWrappedLineLeft(cm: Editor): void;
1856
1857 /** Delete the part of the line from the cursor to the right side of the visual line the cursor is on. */
1858 delWrappedLineRight(cm: Editor): void;
1859
1860 /**
1861 * Undo the last change. Note that, because browsers still don't make it possible for scripts to react to
1862 * or customize the context menu, selecting undo (or redo) from the context menu in a CodeMirror instance does not work.
1863 */
1864 undo(cm: Editor): void;
1865
1866 /** Redo the last undone change. */
1867 redo(cm: Editor): void;
1868
1869 /** Undo the last change to the selection, or if there are no selection-only changes at the top of the history, undo the last change. */
1870 undoSelection(cm: Editor): void;
1871
1872 /** Redo the last change to the selection, or the last text change if no selection changes remain. */
1873 redoSelection(cm: Editor): void;
1874
1875 /** Move the cursor to the start of the document. */
1876 goDocStart(cm: Editor): void;
1877
1878 /** Move the cursor to the end of the document. */
1879 goDocEnd(cm: Editor): void;
1880
1881 /** Move the cursor to the start of the line. */
1882 goLineStart(cm: Editor): void;
1883
1884 /** Move to the start of the text on the line, or if we are already there, to the actual start of the line (including whitespace). */
1885 goLineStartSmart(cm: Editor): void;
1886
1887 /** Move the cursor to the end of the line. */
1888 goLineEnd(cm: Editor): void;
1889
1890 /** Move the cursor to the right side of the visual line it is on. */
1891 goLineRight(cm: Editor): void;
1892
1893 /** Move the cursor to the left side of the visual line it is on. If this line is wrapped, that may not be the start of the line. */
1894 goLineLeft(cm: Editor): void;
1895
1896 /** Move the cursor to the left side of the visual line it is on. If that takes it to the start of the line, behave like goLineStartSmart. */
1897 goLineLeftSmart(cm: Editor): void;
1898
1899 /** Move the cursor up one line. */
1900 goLineUp(cm: Editor): void;
1901
1902 /** Move down one line. */
1903 goLineDown(cm: Editor): void;
1904
1905 /** Move the cursor up one screen, and scroll up by the same distance. */
1906 goPageUp(cm: Editor): void;
1907
1908 /** Move the cursor down one screen, and scroll down by the same distance. */
1909 goPageDown(cm: Editor): void;
1910
1911 /** Move the cursor one character left, going to the previous line when hitting the start of line. */
1912 goCharLeft(cm: Editor): void;
1913
1914 /** Move the cursor one character right, going to the next line when hitting the end of line. */
1915 goCharRight(cm: Editor): void;
1916
1917 /** Move the cursor one character left, but don't cross line boundaries. */
1918 goColumnLeft(cm: Editor): void;
1919
1920 /** Move the cursor one character right, don't cross line boundaries. */
1921 goColumnRight(cm: Editor): void;
1922
1923 /** Move the cursor to the start of the previous word. */
1924 goWordLeft(cm: Editor): void;
1925
1926 /** Move the cursor to the end of the next word. */
1927 goWordRight(cm: Editor): void;
1928
1929 /**
1930 * Move to the left of the group before the cursor. A group is a stretch of word characters, a stretch of punctuation
1931 * characters, a newline, or a stretch of more than one whitespace character.
1932 */
1933 goGroupLeft(cm: Editor): void;
1934
1935 /** Move to the right of the group after the cursor (see above). */
1936 goGroupRight(cm: Editor): void;
1937
1938 /** Delete the character before the cursor. */
1939 delCharBefore(cm: Editor): void;
1940
1941 /** Delete the character after the cursor. */
1942 delCharAfter(cm: Editor): void;
1943
1944 /** Delete up to the start of the word before the cursor. */
1945 delWordBefore(cm: Editor): void;
1946
1947 /** Delete up to the end of the word after the cursor. */
1948 delWordAfter(cm: Editor): void;
1949
1950 /** Delete to the left of the group before the cursor. */
1951 delGroupBefore(cm: Editor): void;
1952
1953 /** Delete to the start of the group after the cursor. */
1954 delGroupAfter(cm: Editor): void;
1955
1956 /** Auto-indent the current line or selection. */
1957 indentAuto(cm: Editor): void;
1958
1959 /** Indent the current line or selection by one indent unit. */
1960 indentMore(cm: Editor): void;
1961
1962 /** Dedent the current line or selection by one indent unit. */
1963 indentLess(cm: Editor): void;
1964
1965 /** Insert a tab character at the cursor. */
1966 insertTab(cm: Editor): void;
1967
1968 /** Insert the amount of spaces that match the width a tab at the cursor position would have. */
1969 insertSoftTab(cm: Editor): void;
1970
1971 /** If something is selected, indent it by one indent unit. If nothing is selected, insert a tab character. */
1972 defaultTabTab(cm: Editor): void;
1973
1974 /** Swap the characters before and after the cursor. */
1975 transposeChars(cm: Editor): void;
1976
1977 /** Insert a newline and auto-indent the new line. */
1978 newlineAndIndent(cm: Editor): void;
1979
1980 /** Flip the overwrite flag. */
1981 toggleOverwrite(cm: Editor): void;
1982 }
1983
1984 /**
1985 * Commands are parameter-less actions that can be performed on an editor.
1986 * Their main use is for key bindings.
1987 * Commands are defined by adding properties to the CodeMirror.commands object.
1988 */
1989 const commands: CommandActions;
1990
1991 interface MouseSelectionConfiguration {
1992 /**
1993 * The unit by which to select. May be one of the built-in units
1994 * or a function that takes a position and returns a range around
1995 * that, for a custom unit. The default is to return "word" for
1996 * double clicks, "line" for triple clicks, "rectangle" for alt-clicks
1997 * (or, on Chrome OS, meta-shift-clicks), and "single" otherwise.
1998 */
1999 unit?:
2000 | 'char'
2001 | 'word'
2002 | 'line'
2003 | 'rectangle'
2004 | ((cm: Editor, pos: Position) => { from: Position; to: Position }) | undefined;
2005
2006 /**
2007 * Whether to extend the existing selection range or start
2008 * a new one. By default, this is enabled when shift clicking.
2009 */
2010 extend?: boolean | undefined;
2011
2012 /**
2013 * When enabled, this adds a new range to the existing selection,
2014 * rather than replacing it. The default behavior is to enable this
2015 * for command-click on Mac OS, and control-click on other platforms.
2016 */
2017 addNew?: boolean | undefined;
2018
2019 /**
2020 * When the mouse even drags content around inside the editor, this
2021 * controls whether it is copied (false) or moved (true). By default, this
2022 * is enabled by alt-clicking on Mac OS, and ctrl-clicking elsewhere.
2023 */
2024 moveOnDrag?: boolean | undefined;
2025 }
2026}
2027
\No newline at end of file