UNPKG

97.6 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: 5.0
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
554 off<T extends keyof EditorEventMap>(eventName: T, handler: EditorEventMap[T]): void;
555 off<K extends DOMEvent & keyof GlobalEventHandlersEventMap>(
556 eventName: K,
557 handler: (instance: Editor, event: GlobalEventHandlersEventMap[K]) => void,
558 ): void;
559
560 /** Expose the state object, so that the Editor.state.completionActive property is reachable */
561 state: any;
562 }
563
564 interface EditorFromTextArea extends Editor {
565 /** Copy the content of the editor into the textarea. */
566 save(): void;
567
568 /** Remove the editor, and restore the original textarea (with the editor's current content). */
569 toTextArea(): void;
570
571 /** Returns the textarea that the instance was based on. */
572 getTextArea(): HTMLTextAreaElement;
573 }
574
575 interface ModeSpecOptions {
576 /** Below options are supported in CSS mode */
577
578 /** Whether to highlight non-standard CSS property keywords such as margin-inline or zoom (default: true). */
579 highlightNonStandardPropertyKeywords?: boolean | undefined;
580
581 /** Below options are supported in Cython/Python modes */
582
583 /** The version of Python to recognize. Default is 3. */
584 version?: 2 | 3 | undefined;
585 /**
586 * If you have a single-line string that is not terminated at the end of the line, this will show subsequent
587 * lines as errors if true, otherwise it will consider the newline as the end of the string. Default is false.
588 */
589 singleLineStringErrors?: boolean | undefined;
590 /**
591 * If you want to write long arguments to a function starting on a new line, how much that line should be
592 * indented. Defaults to one normal indentation unit.
593 */
594 hangingIndent?: number | undefined;
595 /** Regular Expression for single operator matching */
596 singleOperators?: unknown | undefined;
597 /** Regular Expression for single delimiter matching default :^[\\(\\)\\[\\]\\{\\}@,:`=;\\.] */
598 singleDelimiters?: unknown | undefined;
599 /** Regular Expression for double operators matching, default :^((==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//)|(\\*\\*)) */
600 doubleOperators?: unknown | undefined;
601 /** Regular Expression for double delimiters matching default :^((\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=)) */
602 doubleDelimiters?: unknown | undefined;
603 /** Regular Expression for triple delimiters matching default :^((//=)|(>>=)|(<<=)|(\\*\\*=)) */
604 tripleDelimiters?: unknown | undefined;
605 /** RegEx - Regular Expression for identifier, default :^[_A-Za-z][_A-Za-z0-9]* */
606 identifiers?: unknown | undefined;
607 /** List of extra words ton consider as keywords */
608 extra_keywords?: string[] | undefined;
609 /** List of extra words ton consider as builtins */
610 extra_builtins?: string[] | undefined;
611
612 /** useCPP, which determines whether C preprocessor directives are recognized. */
613 useCPP?: boolean | undefined;
614
615 /** Below options are supported in Handlebars/Haskell/YAML front matter mode */
616 base?: string | undefined;
617
618 /** Below options are supported in HTML mixed mode */
619 tags?: {[key: string]: unknown} | undefined;
620
621 /** Below options are supported in JavaScript mixed mode */
622
623 /** json which will set the mode to expect JSON data rather than a JavaScript program. */
624 json?: boolean | undefined;
625 /** jsonld which will set the mode to expect JSON-LD linked data rather than a JavaScript program */
626 jsonld?: boolean | undefined;
627 /** typescript which will activate additional syntax highlighting and some other things for TypeScript code */
628 typescript?: boolean | undefined;
629 /**
630 * trackScope can be set to false to turn off tracking of local variables. This will prevent locals from getting
631 * the "variable-2" token type, and will break completion of locals with javascript-hint.
632 */
633 trackScope?: boolean | undefined;
634 /**
635 * statementIndent which (given a number) will determine the amount of indentation to use for statements
636 * continued on a new line.
637 */
638 statementIndent?: boolean | undefined;
639 /**
640 * wordCharacters, a regexp that indicates which characters should be considered part of an identifier.
641 * Defaults to /[\w$]/, which does not handle non-ASCII identifiers. Can be set to something more elaborate to
642 * improve Unicode support.
643 */
644 wordCharacters?: unknown | undefined;
645
646 /** Below options are supported in Markdown mixed mode */
647
648 /** Whether to separately highlight markdown meta characters (*[]()etc.) (default: false). */
649 highlightFormatting?: boolean | undefined;
650 /** Maximum allowed blockquote nesting (default: 0 - infinite nesting). */
651 maxBlockquoteDepth?: boolean | undefined;
652 /** Whether to highlight inline XML (default: true). */
653 xml?: boolean | undefined;
654 /**
655 * Whether to syntax-highlight fenced code blocks, if given mode is included, or fencedCodeBlockDefaultMode
656 * is set (default: true).
657 */
658 fencedCodeBlockHighlighting?: boolean | undefined;
659 /** Mode to use for fencedCodeBlockHighlighting, if given mode is not included. */
660 fencedCodeBlockDefaultMode?: string | undefined;
661 /** When you want to override default token type names (e.g. {code: "code"}). */
662 tokenTypeOverrides?: unknown | undefined;
663 /** Allow lazy headers without whitespace between hashtag and text (default: false). */
664 allowAtxHeaderWithoutSpace?: boolean | undefined;
665
666 /** Below options are supported in GFM mode mode */
667 gitHubSpice?: boolean | undefined;
668 taskLists?: boolean | undefined;
669 strikethrough?: boolean | undefined;
670 emoji?: boolean | undefined;
671
672 /** Below options are supported in Smarty mode */
673
674 /** leftDelimiter and rightDelimiter, which should be strings that determine where the Smarty syntax starts and ends. */
675 leftDelimiter?: string | undefined;
676 rightDelimiter?: string | undefined;
677 baseMode?: string | undefined;
678
679 /** Below options are supported in sTeX mode */
680
681 /** Whether to start parsing in math mode (default: false) */
682 inMathMode?: boolean | undefined;
683
684 /** Below options are supported in SystemVerilog mode */
685
686 /** List of keywords which should not cause indentation to increase. */
687 noIndentKeywords?: unknown | undefined;
688
689 /** Below options are supported in VHDL mode */
690
691 /** List of atom words. Default: "null" */
692 atoms?: unknown | undefined;
693 /** List of meta hooks. Default: ["`", "$"] */
694 hooks?: unknown | undefined;
695 /** Whether multi-line strings are accepted. Default: false */
696 multiLineStrings?: boolean | undefined;
697
698 /** Below options are supported in XML mode */
699
700 /**
701 * This switches the mode to parse HTML instead of XML. This means attributes do not have to be quoted,
702 * and some elements (such as br) do not require a closing tag.
703 */
704 htmlMode?: boolean | undefined;
705 /**
706 * Controls whether the mode checks that close tags match the corresponding opening tag,
707 * and highlights mismatches as errors. Defaults to true.
708 */
709 matchClosing?: boolean | undefined;
710 /** Setting this to true will force the opening tag of CDATA blocks to not be indented. */
711 alignCDATA?: boolean | undefined;
712 }
713
714 type ModeSpec<T> = {
715 [P in keyof T]: T[P];
716 } & { name: string };
717
718 interface SelectionOptions {
719 /**
720 * Determines whether the selection head should be scrolled into view. Defaults to true.
721 */
722 scroll?: boolean | undefined;
723
724 /**
725 * Determines whether the selection history event may be merged with the previous one.
726 * When an origin starts with the character +, and the last recorded selection had the same origin
727 * and was similar (close in time, both collapsed or both non-collapsed), the new one will replace
728 * the old one. When it starts with *, it will always replace the previous event (if that had the same
729 * origin). Built-in motion uses the "+move" origin. User input uses the "+input" origin.
730 */
731 origin?: string | undefined;
732
733 /**
734 * Determine the direction into which the selection endpoints should be adjusted when they fall inside
735 * an atomic range. Can be either -1 (backward) or 1 (forward). When not given, the bias will be based
736 * on the relative position of the old selection—the editor will try to move further away from that,
737 * to prevent getting stuck.
738 */
739 bias?: number | undefined;
740 }
741
742 interface DocConstructor {
743 new (text: string, mode?: string | ModeSpec<ModeSpecOptions>, firstLineNumber?: number, lineSep?: string): Doc;
744 (text: string, mode?: string | ModeSpec<ModeSpecOptions>, firstLineNumber?: number, lineSep?: string): Doc;
745 }
746
747 interface DocOrEditor {
748 /** Get the mode option */
749 modeOption: string | ModeSpec<ModeSpecOptions>;
750
751 /** 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"). */
752 getValue(seperator?: string): string;
753
754 /** Set the editor content. */
755 setValue(content: string): void;
756
757 /**
758 * Get the text between the given points in the editor, which should be {line, ch} objects.
759 * An optional third argument can be given to indicate the line separator string to use (defaults to "\n").
760 */
761 getRange(from: Position, to: Position, seperator?: string): string;
762
763 /**
764 * Replace the part of the document between from and to with the given string.
765 * from and to must be {line, ch} objects. to can be left off to simply insert the string at position from.
766 */
767 replaceRange(
768 replacement: string | string[],
769 from: Position,
770 to?: Position,
771 origin?: string,
772 ): void;
773
774 /** Get the content of line n. */
775 getLine(n: number): string;
776
777 /** Set the content of line n. */
778 setLine(n: number, text: string): void;
779
780 /** Remove the given line from the document. */
781 removeLine(n: number): void;
782
783 /** Get the number of lines in the editor. */
784 lineCount(): number;
785
786 /**
787 * Get the first line of the editor. This will usually be zero but for linked sub-views,
788 * or documents instantiated with a non-zero first line, it might return other values.
789 */
790 firstLine(): number;
791
792 /** Get the last line of the editor. This will usually be lineCount() - 1, but for linked sub-views, it might return other values. */
793 lastLine(): number;
794
795 /** Fetches the line handle for the given line number. */
796 getLineHandle(num: number): LineHandle;
797
798 /** Given a line handle, returns the current position of that line (or null when it is no longer in the document). */
799 getLineNumber(handle: LineHandle): number | null;
800
801 /**
802 * Iterate over the whole document, and call f for each line, passing the line handle.
803 * This is a faster way to visit a range of line handlers than calling getLineHandle for each of them.
804 * Note that line handles have a text property containing the line's content (as a string).
805 */
806 eachLine(f: (line: LineHandle) => void): void;
807
808 /**
809 * Iterate over the range from start up to (not including) end, and call f for each line, passing the line handle.
810 * This is a faster way to visit a range of line handlers than calling getLineHandle for each of them.
811 * Note that line handles have a text property containing the line's content (as a string).
812 */
813 eachLine(start: number, end: number, f: (line: LineHandle) => void): void;
814
815 /**
816 * Set the editor content as 'clean', a flag that it will retain until it is edited, and which will be set again
817 * when such an edit is undone again. Useful to track whether the content needs to be saved. This function is deprecated
818 * in favor of changeGeneration, which allows multiple subsystems to track different notions of cleanness without interfering.
819 */
820 markClean(): void;
821
822 /**
823 * Returns a number that can later be passed to isClean to test whether any edits were made (and not undone) in the
824 * meantime. If closeEvent is true, the current history event will be ‘closed’, meaning it can't be combined with further
825 * changes (rapid typing or deleting events are typically combined).
826 */
827 changeGeneration(closeEvent?: boolean): number;
828
829 /**
830 * Returns whether the document is currently clean — not modified since initialization or the last call to markClean if
831 * no argument is passed, or since the matching call to changeGeneration if a generation value is given.
832 */
833 isClean(generation?: number): boolean;
834
835 /** Get the currently selected code. */
836 getSelection(): string;
837
838 /** Returns an array containing a string for each selection, representing the content of the selections. */
839 getSelections(lineSep?: string): string[];
840
841 /**
842 * Replace the selection with the given string. By default, the new selection will span the inserted text.
843 * 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.
844 */
845 replaceSelection(replacement: string, collapse?: string): void;
846
847 /**
848 * Replaces the content of the selections with the strings in the array.
849 * The length of the given array should be the same as the number of active selections.
850 * The collapse argument works the same as in replaceSelection.
851 */
852 replaceSelections(replacements: string[], collapse?: string): void;
853
854 /**
855 * start is a an optional string indicating which end of the selection to return.
856 * It may be "from", "to", "head" (the side of the selection that moves when you press shift+arrow),
857 * or "anchor" (the fixed side of the selection).Omitting the argument is the same as passing "head". A {line, ch} object will be returned.
858 */
859 getCursor(start?: string): Position;
860
861 /**
862 * Retrieves a list of all current selections. These will always be sorted, and never overlap (overlapping selections are merged).
863 * Each object in the array contains anchor and head properties referring to {line, ch} objects.
864 */
865 listSelections(): Range[];
866
867 /** Return true if any text is selected. */
868 somethingSelected(): boolean;
869
870 /**
871 * Set the cursor position. You can either pass a single {line, ch} object, or the line and the character as two separate parameters.
872 * Will replace all selections with a single, empty selection at the given position.
873 * The supported options are the same as for setSelection
874 */
875 setCursor(
876 pos: Position | number,
877 ch?: number,
878 options?: { bias?: number | undefined; origin?: string | undefined; scroll?: boolean | undefined },
879 ): void;
880
881 /** Set a single selection range. anchor and head should be {line, ch} objects. head defaults to anchor when not given. */
882 setSelection(
883 anchor: Position,
884 head?: Position,
885 options?: { bias?: number | undefined; origin?: string | undefined; scroll?: boolean | undefined },
886 ): void;
887
888 /**
889 * Sets a new set of selections. There must be at least one selection in the given array. When primary is a
890 * number, it determines which selection is the primary one. When it is not given, the primary index is taken from
891 * the previous selection, or set to the last range if the previous selection had less ranges than the new one.
892 * Supports the same options as setSelection.
893 */
894 setSelections(
895 ranges: Array<{ anchor: Position; head: Position }>,
896 primary?: number,
897 options?: SelectionOptions,
898 ): void;
899
900 /**
901 * Adds a new selection to the existing set of selections, and makes it the primary selection.
902 */
903 addSelection(anchor: Position, head?: Position): void;
904
905 /**
906 * Similar to setSelection, but will, if shift is held or the extending flag is set,
907 * move the head of the selection while leaving the anchor at its current place.
908 * to is optional, and can be passed to ensure a region (for example a word or paragraph) will end up selected
909 * (in addition to whatever lies between that region and the current anchor). When multiple selections
910 * are present, all but the primary selection will be dropped by this method. Supports the same options
911 * as setSelection.
912 */
913 extendSelection(from: Position, to?: Position, options?: SelectionOptions): void;
914
915 /**
916 * An equivalent of extendSelection that acts on all selections at once.
917 */
918 extendSelections(heads: Position[], options?: SelectionOptions): void;
919
920 /**
921 * Applies the given function to all existing selections, and calls extendSelections on the result.
922 */
923 extendSelectionsBy(f: (range: Range) => Position): void;
924
925 /**
926 * Sets or clears the 'extending' flag , which acts similar to the shift key,
927 * in that it will cause cursor movement and calls to extendSelection to leave the selection anchor in place.
928 */
929 setExtending(value: boolean): void;
930
931 /**
932 * Get the value of the 'extending' flag.
933 */
934 getExtending(): boolean;
935
936 /** 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. */
937 linkedDoc(options: {
938 /**
939 * When turned on, the linked copy will share an undo history with the original.
940 * Thus, something done in one of the two can be undone in the other, and vice versa.
941 */
942 sharedHist?: boolean | undefined;
943 from?: number | undefined;
944 /**
945 * Can be given to make the new document a subview of the original. Subviews only show a given range of lines.
946 * Note that line coordinates inside the subview will be consistent with those of the parent,
947 * so that for example a subview starting at line 10 will refer to its first line as line 10, not 0.
948 */
949 to?: number | undefined;
950 /** 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. */
951 mode?: string | ModeSpec<ModeSpecOptions> | undefined;
952 }): Doc;
953
954 /**
955 * Break the link between two documents. After calling this , changes will no longer propagate between the documents,
956 * and, if they had a shared history, the history will become separate.
957 */
958 unlinkDoc(doc: Doc): void;
959
960 /**
961 * Will call the given function for all documents linked to the target document. It will be passed two arguments,
962 * the linked document and a boolean indicating whether that document shares history with the target.
963 */
964 iterLinkedDocs(fn: (doc: Doc, sharedHist: boolean) => void): void;
965
966 /** Undo one edit (if any undo events are stored). */
967 undo(): void;
968
969 /** Redo one undone edit. */
970 redo(): void;
971
972 /**
973 * Undo one edit or selection change.
974 */
975 undoSelection(): void;
976
977 /**
978 * Redo one undone edit or selection change.
979 */
980 redoSelection(): void;
981
982 /** Returns an object with {undo, redo } properties , both of which hold integers , indicating the amount of stored undo and redo operations. */
983 historySize(): { undo: number; redo: number };
984
985 /** Clears the editor's undo history. */
986 clearHistory(): void;
987
988 /** Get a (JSON - serializeable) representation of the undo history. */
989 getHistory(): any;
990
991 /**
992 * Replace the editor's undo history with the one provided, which must be a value as returned by getHistory.
993 * Note that this will have entirely undefined results if the editor content isn't also the same as it was when getHistory was called.
994 */
995 setHistory(history: any): void;
996
997 /** Can be used to mark a range of text with a specific CSS class name. from and to should be { line , ch } objects. */
998 markText(
999 from: Position,
1000 to: Position,
1001 options?: TextMarkerOptions,
1002 ): TextMarker<MarkerRange>;
1003
1004 /**
1005 * Inserts a bookmark, a handle that follows the text around it as it is being edited, at the given position.
1006 * A bookmark has two methods find() and clear(). The first returns the current position of the bookmark, if it is still in the document,
1007 * and the second explicitly removes the bookmark.
1008 */
1009 setBookmark(
1010 pos: Position,
1011 options?: {
1012 /** Can be used to display a DOM node at the current location of the bookmark (analogous to the replacedWith option to markText). */
1013 widget?: HTMLElement | undefined;
1014
1015 /**
1016 * By default, text typed when the cursor is on top of the bookmark will end up to the right of the bookmark.
1017 * Set this option to true to make it go to the left instead.
1018 */
1019 insertLeft?: boolean | undefined;
1020
1021 /**
1022 * When the target document is linked to other documents, you can set shared to true to make the marker appear in all documents.
1023 * By default, a marker appears only in its target document.
1024 */
1025 shared?: boolean | undefined;
1026
1027 /** As with markText, this determines whether mouse events on the widget inserted for this bookmark are handled by CodeMirror. The default is false. */
1028 handleMouseEvents?: boolean | undefined;
1029 },
1030 ): TextMarker<Position>;
1031
1032 /** Returns an array of all the bookmarks and marked ranges found between the given positions. */
1033 findMarks(from: Position, to: Position): TextMarker[];
1034
1035 /** Returns an array of all the bookmarks and marked ranges present at the given position. */
1036 findMarksAt(pos: Position): TextMarker[];
1037
1038 /** Returns an array containing all marked ranges in the document. */
1039 getAllMarks(): TextMarker[];
1040
1041 /**
1042 * 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.
1043 * 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.
1044 * options, when given, should be an object that configures the behavior of the widget.
1045 * 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.
1046 */
1047 addLineWidget(line: any, node: HTMLElement, options?: LineWidgetOptions): LineWidget;
1048
1049 /** Remove the line widget */
1050 removeLineWidget(widget: LineWidget): void;
1051
1052 /**
1053 * Gets the mode object for the editor. Note that this is distinct from getOption("mode"), which gives you the mode specification,
1054 * rather than the resolved, instantiated mode object.
1055 */
1056 getMode(): Mode<unknown>;
1057
1058 /** 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. */
1059 lineSeparator(): string;
1060
1061 /**
1062 * Calculates and returns a { line , ch } object for a zero-based index whose value is relative to the start of the editor's text.
1063 * If the index is out of range of the text then the returned object is clipped to start or end of the text respectively.
1064 */
1065 posFromIndex(index: number): Position;
1066
1067 /** The reverse of posFromIndex. */
1068 indexFromPos(object: Position): number;
1069
1070 /** Expose the state object, so that the Doc.state.completionActive property is reachable */
1071 state: any;
1072 }
1073
1074 interface Doc extends DocOrEditor {
1075 /** Retrieve the editor associated with a document. May return null. */
1076 getEditor(): Editor | null;
1077
1078 /** Create an identical copy of the given doc. When copyHistory is true , the history will also be copied. */
1079 copy(copyHistory: boolean): Doc;
1080
1081 on<T extends keyof DocEventMap>(eventName: T, handler: DocEventMap[T]): void;
1082 off<T extends keyof DocEventMap>(eventName: T, handler: DocEventMap[T]): void;
1083 }
1084
1085 interface LineHandle {
1086 text: string;
1087 on<T extends keyof LineHandleEventMap>(eventName: T, handler: LineHandleEventMap[T]): void;
1088 off<T extends keyof LineHandleEventMap>(leventName: T, handler: LineHandleEventMap[T]): void;
1089 }
1090
1091 interface ScrollInfo {
1092 left: number;
1093 top: number;
1094 width: number;
1095 height: number;
1096 clientWidth: number;
1097 clientHeight: number;
1098 }
1099
1100 interface MarkerRange {
1101 from: Position;
1102 to: Position;
1103 }
1104
1105 interface TextMarker<T = MarkerRange | Position> extends Partial<TextMarkerOptions> {
1106 /** Remove the mark. */
1107 clear(): void;
1108
1109 /**
1110 * Returns a {from, to} object (both holding document positions), indicating the current position of the marked range,
1111 * or undefined if the marker is no longer in the document.
1112 */
1113 find(): T | undefined;
1114
1115 /** Called when you've done something that might change the size of the marker and want to cheaply update the display */
1116 changed(): void;
1117
1118 on<T extends keyof TextMarkerEventMap>(eventName: T, handler: TextMarkerEventMap[T]): void;
1119 off<T extends keyof TextMarkerEventMap>(eventName: T, handler: TextMarkerEventMap[T]): void;
1120 }
1121
1122 interface LineWidget {
1123 /** Removes the widget. */
1124 clear(): void;
1125
1126 /**
1127 * Call this if you made some change to the widget's DOM node that might affect its height.
1128 * It'll force CodeMirror to update the height of the line that contains the widget.
1129 */
1130 changed(): void;
1131
1132 on<T extends keyof LineWidgetEventMap>(eventName: T, handler: LineWidgetEventMap[T]): void;
1133 off<T extends keyof LineWidgetEventMap>(eventName: T, handler: LineWidgetEventMap[T]): void;
1134 }
1135
1136 interface LineWidgetOptions {
1137 /** Whether the widget should cover the gutter. */
1138 coverGutter?: boolean | undefined;
1139 /** Whether the widget should stay fixed in the face of horizontal scrolling. */
1140 noHScroll?: boolean | undefined;
1141 /** Causes the widget to be placed above instead of below the text of the line. */
1142 above?: boolean | undefined;
1143 /** When true, will cause the widget to be rendered even if the line it is associated with is hidden. */
1144 showIfHidden?: boolean | undefined;
1145 /**
1146 * Determines whether the editor will capture mouse and drag events occurring in this widget.
1147 * Default is false—the events will be left alone for the default browser handler, or specific handlers on the widget, to capture.
1148 */
1149 handleMouseEvents?: boolean | undefined;
1150 /**
1151 * By default, the widget is added below other widgets for the line.
1152 * 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).
1153 * Note that this only has effect once, when the widget is created.
1154 */
1155 insertAt?: number | undefined;
1156 /** Add an extra CSS class name to the wrapper element created for the widget. */
1157 className?: string | undefined;
1158 }
1159
1160 interface EditorChange {
1161 /** Position (in the pre-change coordinate system) where the change started. */
1162 from: Position;
1163 /** Position (in the pre-change coordinate system) where the change ended. */
1164 to: Position;
1165 /** Array of strings representing the text that replaced the changed range (split by line). */
1166 text: string[];
1167 /** Text that used to be between from and to, which is overwritten by this change. */
1168 removed?: string[] | undefined;
1169 /** String representing the origin of the change event and whether it can be merged with history */
1170 origin?: string | undefined;
1171 }
1172
1173 interface EditorChangeCancellable extends EditorChange {
1174 /**
1175 * 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.
1176 * If the change came from undo/redo, `update` is undefined and the change cannot be modified.
1177 */
1178 update?(from?: Position, to?: Position, text?: string[]): void;
1179
1180 cancel(): void;
1181 }
1182
1183 interface PositionConstructor {
1184 new (line: number, ch?: number, sticky?: string): Position;
1185 (line: number, ch?: number, sticky?: string): Position;
1186 }
1187
1188 interface EditorSelectionChange {
1189 ranges: Range[];
1190 update(ranges: Range[]): void;
1191 origin?: string | undefined;
1192 }
1193
1194 interface Range {
1195 anchor: Position;
1196 head: Position;
1197 from(): Position;
1198 to(): Position;
1199 empty(): boolean;
1200 }
1201
1202 interface Position {
1203 ch: number;
1204 line: number;
1205 sticky?: string | undefined;
1206 }
1207
1208 interface ScrollbarMeasure {
1209 clientHeight: number;
1210 viewHeight: number;
1211 scrollWidth: number;
1212 viewWidth: number;
1213 barLeft: number;
1214 docHeight: number;
1215 scrollHeight: number;
1216 nativeBarWidth: number;
1217 gutterWidth: number;
1218 }
1219
1220 interface ScrollbarModel {
1221 update(measure: ScrollbarMeasure): { bottom: number, right: number };
1222 clear(): void;
1223 setScrollLeft(pos: number): void;
1224 setScrollTop(pos: number): void;
1225 }
1226
1227 interface ScrollbarModelConstructor {
1228 new(place: (node: Element) => void, scroll: (pos: number, axis: 'horizontal' | 'vertical') => void): ScrollbarModel;
1229 }
1230
1231 interface ScrollbarModels {
1232 native: ScrollbarModelConstructor;
1233 null: ScrollbarModelConstructor;
1234 }
1235
1236 const scrollbarModel: ScrollbarModels;
1237
1238 type InputStyle = 'textarea' | 'contenteditable';
1239
1240 interface EditorConfiguration {
1241 /** The starting value of the editor. Can be a string, or a document object. */
1242 value?: string | Doc | undefined;
1243
1244 /**
1245 * string|object. The mode to use. When not given, this will default to the first mode that was loaded.
1246 * It may be a string, which either simply names the mode or is a MIME type associated with the mode.
1247 * Alternatively, it may be an object containing configuration options for the mode,
1248 * with a name property that names the mode (for example {name: "javascript", json: true}).
1249 */
1250 mode?: string | ModeSpec<ModeSpecOptions> | undefined;
1251
1252 /**
1253 * Explicitly set the line separator for the editor. By default (value null), the document will be split on CRLFs as well
1254 * as lone CRs and LFs, and a single LF will be used as line separator in all output (such as getValue). When a specific
1255 * string is given, lines will only be split on that string, and output will, by default, use that same separator.
1256 */
1257 lineSeparator?: string | null | undefined;
1258
1259 /**
1260 * The theme to style the editor with. You must make sure the CSS file defining the corresponding .cm-s-[name] styles is loaded.
1261 * The default is "default".
1262 */
1263 theme?: string | undefined;
1264
1265 /** How many spaces a block (whatever that means in the edited language) should be indented. The default is 2. */
1266 indentUnit?: number | undefined;
1267
1268 /** Whether to use the context-sensitive indentation that the mode provides (or just indent the same as the line before). Defaults to true. */
1269 smartIndent?: boolean | undefined;
1270
1271 /** The width of a tab character. Defaults to 4. */
1272 tabSize?: number | undefined;
1273
1274 /** Whether, when indenting, the first N*tabSize spaces should be replaced by N tabs. Default is false. */
1275 indentWithTabs?: boolean | undefined;
1276
1277 /**
1278 * Configures whether the editor should re-indent the current line when a character is typed
1279 * that might change its proper indentation (only works if the mode supports indentation). Default is true.
1280 */
1281 electricChars?: boolean | undefined;
1282
1283 /**
1284 * A regular expression used to determine which characters should be replaced by a special placeholder. Mostly useful for non-printing
1285 * special characters. The default is /[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b-\u200f\u2028\u2029\ufeff\ufff9-\ufffc]/.
1286 */
1287 specialChars?: RegExp | undefined;
1288
1289 /**
1290 * A function that, given a special character identified by the specialChars option, produces a DOM node that is used to
1291 * represent the character. By default, a red dot (•) is shown, with a title tooltip to indicate the character code.
1292 */
1293 specialCharPlaceholder?: ((char: string) => HTMLElement) | undefined;
1294
1295 /**
1296 * Flips overall layout and selects base paragraph direction to be left-to-right or right-to-left. Default is "ltr". CodeMirror
1297 * applies the Unicode Bidirectional Algorithm to each line, but does not autodetect base direction — it's set to the editor
1298 * direction for all lines. The resulting order is sometimes wrong when base direction doesn't match user intent (for example,
1299 * leading and trailing punctuation jumps to the wrong side of the line). Therefore, it's helpful for multilingual input to let
1300 * users toggle this option.
1301 */
1302 direction?: "ltr" | "rtl" | undefined;
1303
1304 /**
1305 * Determines whether horizontal cursor movement through right-to-left (Arabic, Hebrew) text
1306 * is visual (pressing the left arrow moves the cursor left)
1307 * or logical (pressing the left arrow moves to the next lower index in the string, which is visually right in right-to-left text).
1308 * The default is false on Windows, and true on other platforms.
1309 */
1310 rtlMoveVisually?: boolean | undefined;
1311
1312 /**
1313 * Configures the keymap to use. The default is "default", which is the only keymap defined in codemirror.js itself.
1314 * Extra keymaps are found in the keymap directory. See the section on keymaps for more information.
1315 */
1316 keyMap?: string | undefined;
1317
1318 /** 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. */
1319 extraKeys?: string | KeyMap | undefined;
1320
1321 /** Allows you to configure the behavior of mouse selection and dragging. The function is called when the left mouse button is pressed. */
1322 configureMouse?: ((
1323 cm: Editor,
1324 repeat: 'single' | 'double' | 'triple',
1325 event: Event,
1326 ) => MouseSelectionConfiguration) | undefined;
1327
1328 /** Whether CodeMirror should scroll or wrap for long lines. Defaults to false (scroll). */
1329 lineWrapping?: boolean | undefined;
1330
1331 /** Whether to show line numbers to the left of the editor. */
1332 lineNumbers?: boolean | undefined;
1333
1334 /** At which number to start counting lines. Default is 1. */
1335 firstLineNumber?: number | undefined;
1336
1337 /** 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. */
1338 lineNumberFormatter?: ((line: number) => string) | undefined;
1339
1340 /**
1341 * Can be used to add extra gutters (beyond or instead of the line number gutter).
1342 * Should be an array of CSS class names, each of which defines a width (and optionally a background),
1343 * and which will be used to draw the background of the gutters.
1344 * May include the CodeMirror-linenumbers class, in order to explicitly set the position of the line number gutter
1345 * (it will default to be to the right of all other gutters). These class names are the keys passed to setGutterMarker.
1346 */
1347 gutters?: Array<string | { className: string; style?: string | undefined }> | undefined;
1348
1349 /**
1350 * Determines whether the gutter scrolls along with the content horizontally (false)
1351 * or whether it stays fixed during horizontal scrolling (true, the default).
1352 */
1353 fixedGutter?: boolean | undefined;
1354
1355 /**
1356 * Chooses a scrollbar implementation. The default is "native", showing native scrollbars. The core library also
1357 * provides the "null" style, which completely hides the scrollbars. Addons can implement additional scrollbar models.
1358 */
1359 scrollbarStyle?: keyof ScrollbarModels | undefined;
1360
1361 /**
1362 * When fixedGutter is on, and there is a horizontal scrollbar, by default the gutter will be visible to the left of this scrollbar.
1363 * If this option is set to true, it will be covered by an element with class CodeMirror-gutter-filler.
1364 */
1365 coverGutterNextToScrollbar?: boolean | undefined;
1366
1367 /**
1368 * Selects the way CodeMirror handles input and focus.
1369 * The core library defines the "textarea" and "contenteditable" input models.
1370 * On mobile browsers, the default is "contenteditable". On desktop browsers, the default is "textarea".
1371 * Support for IME and screen readers is better in the "contenteditable" model.
1372 */
1373 inputStyle?: InputStyle | undefined;
1374
1375 /** 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. */
1376 readOnly?: boolean | 'nocursor' | undefined;
1377
1378 /** This label is read by the screenreaders when CodeMirror text area is focused. This is helpful for accessibility. */
1379 screenReaderLabel?: string | undefined;
1380
1381 /** Whether the cursor should be drawn when a selection is active. Defaults to false. */
1382 showCursorWhenSelecting?: boolean | undefined;
1383
1384 /** 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. */
1385 lineWiseCopyCut?: boolean | undefined;
1386
1387 /**
1388 * When pasting something from an external source (not from the editor itself), if the number of lines matches the number of selection,
1389 * CodeMirror will by default insert one line per selection. You can set this to false to disable that behavior.
1390 */
1391 pasteLinesPerSelection?: boolean | undefined;
1392
1393 /** Determines whether multiple selections are joined as soon as they touch (the default) or only when they overlap (true). */
1394 selectionsMayTouch?: boolean | undefined;
1395
1396 /** The maximum number of undo levels that the editor stores. Defaults to 40. */
1397 undoDepth?: number | undefined;
1398
1399 /** The period of inactivity (in milliseconds) that will cause a new history event to be started when typing or deleting. Defaults to 500. */
1400 historyEventDelay?: number | undefined;
1401
1402 /** The tab index to assign to the editor. If not given, no tab index will be assigned. */
1403 tabindex?: number | undefined;
1404
1405 /**
1406 * Can be used to make CodeMirror focus itself on initialization. Defaults to off.
1407 * 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,
1408 * or it has an autofocus attribute and no other element is focused.
1409 */
1410 autofocus?: boolean | undefined;
1411
1412 /**
1413 * Some addons run user-visible strings (such as labels in the interface) through the phrase method to allow for translation.
1414 * This option determines the return value of that method. When it is null or an object that doesn't have a property named by
1415 * the input string, that string is returned. Otherwise, the value of the property corresponding to that string is returned.
1416 */
1417 phrases?: {[s: string]: unknown} | undefined;
1418
1419 /** Controls whether drag-and - drop is enabled. On by default. */
1420 dragDrop?: boolean | undefined;
1421
1422 /**
1423 * When set (default is null) only files whose type is in the array can be dropped into the editor.
1424 * The strings should be MIME types, and will be checked against the type of the File object as reported by the browser.
1425 */
1426 allowDropFileTypes?: string[] | null | undefined;
1427
1428 /**
1429 * When given , this will be called when the editor is handling a dragenter , dragover , or drop event.
1430 * It will be passed the editor instance and the event object as arguments.
1431 * 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.
1432 */
1433 onDragEvent?: ((instance: Editor, event: DragEvent) => boolean) | undefined;
1434
1435 /**
1436 * This provides a rather low-level hook into CodeMirror's key handling.
1437 * If provided, this function will be called on every keydown, keyup, and keypress event that CodeMirror captures.
1438 * It will be passed two arguments, the editor instance and the key event.
1439 * This key event is pretty much the raw key event, except that a stop() method is always added to it.
1440 * You could feed it to, for example, jQuery.Event to further normalize it.
1441 * This function can inspect the key event, and handle it if it wants to.
1442 * It may return true to tell CodeMirror to ignore the event.
1443 * Be wary that, on some browsers, stopping a keydown does not stop the keypress from firing, whereas on others it does.
1444 * If you respond to an event, you should probably inspect its type property and only do something when it is keydown
1445 * (or keypress for actions that need character data).
1446 */
1447 onKeyEvent?: ((instance: Editor, event: KeyboardEvent) => boolean) | undefined;
1448
1449 /** Half - period in milliseconds used for cursor blinking. The default blink rate is 530ms. */
1450 cursorBlinkRate?: number | undefined;
1451
1452 /**
1453 * How much extra space to always keep above and below the cursor when
1454 * approaching the top or bottom of the visible view in a scrollable document. Default is 0.
1455 */
1456 cursorScrollMargin?: number | undefined;
1457
1458 /**
1459 * Determines the height of the cursor. Default is 1 , meaning it spans the whole height of the line.
1460 * For some fonts (and by some tastes) a smaller height (for example 0.85),
1461 * which causes the cursor to not reach all the way to the bottom of the line, looks better
1462 */
1463 cursorHeight?: number | undefined;
1464
1465 /**
1466 * Controls whether, when the context menu is opened with a click outside of the current selection,
1467 * the cursor is moved to the point of the click. Defaults to true.
1468 */
1469 resetSelectionOnContextMenu?: boolean | undefined;
1470
1471 /**
1472 * Highlighting is done by a pseudo background thread that will work for workTime milliseconds,
1473 * and then use timeout to sleep for workDelay milliseconds.
1474 * The defaults are 200 and 300, you can change these options to make the highlighting more or less aggressive.
1475 */
1476 workTime?: number | undefined;
1477
1478 /** See workTime. */
1479 workDelay?: number | undefined;
1480
1481 /**
1482 * Indicates how quickly CodeMirror should poll its input textarea for changes(when focused).
1483 * 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.
1484 * Thus, it polls. Default is 100 milliseconds.
1485 */
1486 pollInterval?: number | undefined;
1487
1488 /**
1489 * By default, CodeMirror will combine adjacent tokens into a single span if they have the same class.
1490 * This will result in a simpler DOM tree, and thus perform better. With some kinds of styling(such as rounded corners),
1491 * this will change the way the document looks. You can set this option to false to disable this behavior.
1492 */
1493 flattenSpans?: boolean | undefined;
1494
1495 /**
1496 * 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-".
1497 * For example, tokens from the XML mode will get the cm-m-xml class.
1498 */
1499 addModeClass?: boolean | undefined;
1500
1501 /**
1502 * When highlighting long lines, in order to stay responsive, the editor will give up and simply style
1503 * the rest of the line as plain text when it reaches a certain position. The default is 10000.
1504 * You can set this to Infinity to turn off this behavior.
1505 */
1506 maxHighlightLength?: number | undefined;
1507
1508 /**
1509 * Specifies the amount of lines that are rendered above and below the part of the document that's currently scrolled into view.
1510 * This affects the amount of updates needed when scrolling, and the amount of work that such an update does.
1511 * You should usually leave it at its default, 10. Can be set to Infinity to make sure the whole document is always rendered,
1512 * and thus the browser's text search works on it. This will have bad effects on performance of big documents.
1513 */
1514 viewportMargin?: number | undefined;
1515
1516 /** Specifies whether or not spellcheck will be enabled on the input. */
1517 spellcheck?: boolean | undefined;
1518
1519 /** Specifies whether or not autocorrect will be enabled on the input. */
1520 autocorrect?: boolean | undefined;
1521
1522 /** Specifies whether or not autocapitalization will be enabled on the input. */
1523 autocapitalize?: boolean | undefined;
1524 }
1525
1526 interface TextMarkerOptions {
1527 /** Assigns a CSS class to the marked stretch of text. */
1528 className?: string | undefined;
1529
1530 /** Determines whether text inserted on the left of the marker will end up inside or outside of it. */
1531 inclusiveLeft?: boolean | undefined;
1532
1533 /** Like inclusiveLeft, but for the right side. */
1534 inclusiveRight?: boolean | undefined;
1535
1536 /** 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. */
1537 selectLeft?: boolean | undefined;
1538
1539 /** Like selectLeft, but for the right side. */
1540 selectRight?: boolean | undefined;
1541
1542 /**
1543 * Atomic ranges act as a single unit when cursor movement is concerned — i.e. it is impossible to place the cursor inside of them.
1544 * You can control whether the cursor is allowed to be placed directly before or after them using selectLeft or selectRight.
1545 * If selectLeft (or right) is not provided, then inclusiveLeft (or right) will control this behavior.
1546 */
1547 atomic?: boolean | undefined;
1548
1549 /** Collapsed ranges do not show up in the display. Setting a range to be collapsed will automatically make it atomic. */
1550 collapsed?: boolean | undefined;
1551
1552 /**
1553 * When enabled, will cause the mark to clear itself whenever the cursor enters its range.
1554 * This is mostly useful for text - replacement widgets that need to 'snap open' when the user tries to edit them.
1555 * The "clear" event fired on the range handle can be used to be notified when this happens.
1556 */
1557 clearOnEnter?: boolean | undefined;
1558
1559 /** Determines whether the mark is automatically cleared when it becomes empty. Default is true. */
1560 clearWhenEmpty?: boolean | undefined;
1561
1562 /**
1563 * Use a given node to display this range. Implies both collapsed and atomic.
1564 * The given DOM node must be an inline element (as opposed to a block element).
1565 */
1566 replacedWith?: HTMLElement | undefined;
1567
1568 /**
1569 * When replacedWith is given, this determines whether the editor will
1570 * capture mouse and drag events occurring in this widget. Default is
1571 * false—the events will be left alone for the default browser handler,
1572 * or specific handlers on the widget, to capture.
1573 */
1574 handleMouseEvents?: boolean | undefined;
1575
1576 /**
1577 * A read-only span can, as long as it is not cleared, not be modified except by calling setValue to reset the whole document.
1578 * Note: adding a read-only span currently clears the undo history of the editor,
1579 * because existing undo events being partially nullified by read - only spans would corrupt the history (in the current implementation).
1580 */
1581 readOnly?: boolean | undefined;
1582
1583 /** 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). */
1584 addToHistory?: boolean | undefined;
1585
1586 /** Can be used to specify an extra CSS class to be applied to the leftmost span that is part of the marker. */
1587 startStyle?: string | undefined;
1588
1589 /** Equivalent to startStyle, but for the rightmost span. */
1590 endStyle?: string | undefined;
1591
1592 /** A string of CSS to be applied to the covered text. For example "color: #fe3". */
1593 css?: string | undefined;
1594
1595 /** When given, will give the nodes created for this span a HTML title attribute with the given value. */
1596 title?: string | undefined;
1597
1598 /** 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. */
1599 attributes?: { [name: string]: string } | undefined;
1600
1601 /**
1602 * When the target document is linked to other documents, you can set shared to true to make the marker appear in all documents.
1603 * By default, a marker appears only in its target document.
1604 */
1605 shared?: boolean | undefined;
1606 }
1607
1608 class StringStream {
1609 constructor(text: string);
1610 lastColumnPos: number;
1611 lastColumnValue: number;
1612 lineStart: number;
1613
1614 /**
1615 * Current position in the string.
1616 */
1617 pos: number;
1618
1619 /**
1620 * Where the stream's position was when it was first passed to the token function.
1621 */
1622 start: number;
1623
1624 /**
1625 * The current line's content.
1626 */
1627 string: string;
1628
1629 /**
1630 * Number of spaces per tab character.
1631 */
1632 tabSize: number;
1633
1634 /**
1635 * Returns true only if the stream is at the end of the line.
1636 */
1637 eol(): boolean;
1638
1639 /**
1640 * Returns true only if the stream is at the start of the line.
1641 */
1642 sol(): boolean;
1643
1644 /**
1645 * Returns the next character in the stream without advancing it. Will return an null at the end of the line.
1646 */
1647 peek(): string | null;
1648
1649 /**
1650 * Returns the next character in the stream and advances it. Also returns null when no more characters are available.
1651 */
1652 next(): string | null;
1653
1654 /**
1655 * match can be a character, a regular expression, or a function that takes a character and returns a boolean.
1656 * If the next character in the stream 'matches' the given argument, it is consumed and returned.
1657 * Otherwise, undefined is returned.
1658 */
1659 eat(match: string | RegExp | ((char: string) => boolean)): string;
1660
1661 /**
1662 * Repeatedly calls eat with the given argument, until it fails. Returns true if any characters were eaten.
1663 */
1664 eatWhile(match: string | RegExp | ((char: string) => boolean)): boolean;
1665
1666 /**
1667 * Shortcut for eatWhile when matching white-space.
1668 */
1669 eatSpace(): boolean;
1670
1671 /**
1672 * Moves the position to the end of the line.
1673 */
1674 skipToEnd(): void;
1675
1676 /**
1677 * Skips to the next occurrence of the given character, if found on the current line (doesn't advance the stream if
1678 * the character does not occur on the line).
1679 *
1680 * Returns true if the character was found.
1681 */
1682 skipTo(ch: string): boolean;
1683
1684 /**
1685 * Act like a multi-character eat - if consume is true or not given - or a look-ahead that doesn't update the stream
1686 * position - if it is false. pattern can be either a string or a regular expression starting with ^. When it is a
1687 * string, caseFold can be set to true to make the match case-insensitive. When successfully matching a regular
1688 * expression, the returned value will be the array returned by match, in case you need to extract matched groups.
1689 */
1690 match(pattern: string, consume?: boolean, caseFold?: boolean): boolean;
1691 match(pattern: RegExp, consume?: boolean): string[];
1692
1693 /**
1694 * Backs up the stream n characters. Backing it up further than the start of the current token will cause things to
1695 * break, so be careful.
1696 */
1697 backUp(n: number): void;
1698
1699 /**
1700 * Returns the column (taking into account tabs) at which the current token starts.
1701 */
1702 column(): number;
1703
1704 /**
1705 * Tells you how far the current line has been indented, in spaces. Corrects for tab characters.
1706 */
1707 indentation(): number;
1708
1709 /**
1710 * Get the string between the start of the current token and the current stream position.
1711 */
1712 current(): string;
1713
1714 /**
1715 * Returns the content of the line n lines ahead in the stream without
1716 * advancing it. Will return undefined if not found.
1717 */
1718 lookAhead(n: number): string | undefined;
1719 }
1720
1721 /**
1722 * A Mode is, in the simplest case, a lexer (tokenizer) for your language — a function that takes a character stream as input,
1723 * advances it past a token, and returns a style for that token. More advanced modes can also handle indentation for the language.
1724 */
1725 interface Mode<T> {
1726 name?: string | undefined;
1727
1728 /**
1729 * This function should read one token from the stream it is given as an argument, optionally update its state,
1730 * and return a style string, or null for tokens that do not have to be styled. Multiple styles can be returned, separated by spaces.
1731 */
1732 token: (stream: StringStream, state: T) => string | null;
1733
1734 /**
1735 * A function that produces a state object to be used at the start of a document.
1736 */
1737 startState?: (() => T) | undefined;
1738 /**
1739 * For languages that have significant blank lines, you can define a blankLine(state) method on your mode that will get called
1740 * whenever a blank line is passed over, so that it can update the parser state.
1741 */
1742 blankLine?: ((state: T) => void) | undefined;
1743 /**
1744 * Given a state returns a safe copy of that state.
1745 */
1746 copyState?: ((state: T) => T) | undefined;
1747
1748 /**
1749 * Returns the number of spaces of indentation that should be used if a newline were added after the given state. Optionally
1750 * this can use the textAfter string (which is the text after the current position) or the line string, which is the whole
1751 * text of the line.
1752 */
1753 indent?: ((state: T, textAfter: string, line: string) => number) | undefined;
1754
1755 /** The four below strings are used for working with the commenting addon. */
1756 /**
1757 * String that starts a line comment.
1758 */
1759 lineComment?: string | undefined;
1760 /**
1761 * String that starts a block comment.
1762 */
1763 blockCommentStart?: string | undefined;
1764 /**
1765 * String that ends a block comment.
1766 */
1767 blockCommentEnd?: string | undefined;
1768 /**
1769 * String to put at the start of continued lines in a block comment.
1770 */
1771 blockCommentLead?: string | undefined;
1772
1773 /**
1774 * Trigger a reindent whenever one of the characters in the string is typed.
1775 */
1776 electricChars?: string | undefined;
1777 /**
1778 * Trigger a reindent whenever the regex matches the part of the line before the cursor.
1779 */
1780 electricinput?: RegExp | undefined;
1781 }
1782
1783 /**
1784 * A function that, given a CodeMirror configuration object and an optional mode configuration object, returns a mode object.
1785 */
1786 interface ModeFactory<T> {
1787 (config: EditorConfiguration, modeOptions?: any): Mode<T>;
1788 }
1789
1790 /**
1791 * id will be the id for the defined mode. Typically, you should use this second argument to defineMode as your module scope function
1792 * (modes should not leak anything into the global scope!), i.e. write your whole mode inside this function.
1793 */
1794 function defineMode(id: string, modefactory: ModeFactory<any>): void;
1795
1796 /**
1797 * The first argument is a configuration object as passed to the mode constructor function, and the second argument
1798 * is a mode specification as in the EditorConfiguration mode option.
1799 */
1800 function getMode(config: EditorConfiguration, mode: string | ModeSpec<ModeSpecOptions>): Mode<unknown>;
1801
1802 /**
1803 * Utility function from the overlay.js addon that allows modes to be combined. The mode given as the base argument takes care of
1804 * most of the normal mode functionality, but a second (typically simple) mode is used, which can override the style of text.
1805 * 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
1806 * the combine argument was true and not overridden, or state.overlay.combineTokens was true, in which case the styles are combined.
1807 */
1808 function overlayMode(base: Mode<any>, overlay: Mode<any>, combine?: boolean): Mode<any>;
1809
1810 interface ModeMap {
1811 [modeName: string]: ModeFactory<any>;
1812 }
1813
1814 /**
1815 * Maps mode names to their constructors
1816 */
1817 const modes: ModeMap;
1818
1819 function defineMIME(mime: string, modeSpec: string | ModeSpec<ModeSpecOptions>): void;
1820
1821 interface MimeModeMap {
1822 [mimeName: string]: string | ModeSpec<ModeSpecOptions>;
1823 }
1824
1825 /**
1826 * Maps MIME types to mode specs.
1827 */
1828 const mimeModes: MimeModeMap;
1829
1830 interface CommandActions {
1831 /** Select the whole content of the editor. */
1832 selectAll(cm: Editor): void;
1833
1834 /** When multiple selections are present, this deselects all but the primary selection. */
1835 singleSelection(cm: Editor): void;
1836
1837 /** 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. */
1838 killLine(cm: Editor): void;
1839
1840 /** Deletes the whole line under the cursor, including newline at the end. */
1841 deleteLine(cm: Editor): void;
1842
1843 /** Delete the part of the line before the cursor. */
1844 delLineLeft(cm: Editor): void;
1845
1846 /** Delete the part of the line from the left side of the visual line the cursor is on to the cursor. */
1847 delWrappedLineLeft(cm: Editor): void;
1848
1849 /** Delete the part of the line from the cursor to the right side of the visual line the cursor is on. */
1850 delWrappedLineRight(cm: Editor): void;
1851
1852 /**
1853 * Undo the last change. Note that, because browsers still don't make it possible for scripts to react to
1854 * or customize the context menu, selecting undo (or redo) from the context menu in a CodeMirror instance does not work.
1855 */
1856 undo(cm: Editor): void;
1857
1858 /** Redo the last undone change. */
1859 redo(cm: Editor): void;
1860
1861 /** 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. */
1862 undoSelection(cm: Editor): void;
1863
1864 /** Redo the last change to the selection, or the last text change if no selection changes remain. */
1865 redoSelection(cm: Editor): void;
1866
1867 /** Move the cursor to the start of the document. */
1868 goDocStart(cm: Editor): void;
1869
1870 /** Move the cursor to the end of the document. */
1871 goDocEnd(cm: Editor): void;
1872
1873 /** Move the cursor to the start of the line. */
1874 goLineStart(cm: Editor): void;
1875
1876 /** 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). */
1877 goLineStartSmart(cm: Editor): void;
1878
1879 /** Move the cursor to the end of the line. */
1880 goLineEnd(cm: Editor): void;
1881
1882 /** Move the cursor to the right side of the visual line it is on. */
1883 goLineRight(cm: Editor): void;
1884
1885 /** 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. */
1886 goLineLeft(cm: Editor): void;
1887
1888 /** 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. */
1889 goLineLeftSmart(cm: Editor): void;
1890
1891 /** Move the cursor up one line. */
1892 goLineUp(cm: Editor): void;
1893
1894 /** Move down one line. */
1895 goLineDown(cm: Editor): void;
1896
1897 /** Move the cursor up one screen, and scroll up by the same distance. */
1898 goPageUp(cm: Editor): void;
1899
1900 /** Move the cursor down one screen, and scroll down by the same distance. */
1901 goPageDown(cm: Editor): void;
1902
1903 /** Move the cursor one character left, going to the previous line when hitting the start of line. */
1904 goCharLeft(cm: Editor): void;
1905
1906 /** Move the cursor one character right, going to the next line when hitting the end of line. */
1907 goCharRight(cm: Editor): void;
1908
1909 /** Move the cursor one character left, but don't cross line boundaries. */
1910 goColumnLeft(cm: Editor): void;
1911
1912 /** Move the cursor one character right, don't cross line boundaries. */
1913 goColumnRight(cm: Editor): void;
1914
1915 /** Move the cursor to the start of the previous word. */
1916 goWordLeft(cm: Editor): void;
1917
1918 /** Move the cursor to the end of the next word. */
1919 goWordRight(cm: Editor): void;
1920
1921 /**
1922 * Move to the left of the group before the cursor. A group is a stretch of word characters, a stretch of punctuation
1923 * characters, a newline, or a stretch of more than one whitespace character.
1924 */
1925 goGroupLeft(cm: Editor): void;
1926
1927 /** Move to the right of the group after the cursor (see above). */
1928 goGroupRight(cm: Editor): void;
1929
1930 /** Delete the character before the cursor. */
1931 delCharBefore(cm: Editor): void;
1932
1933 /** Delete the character after the cursor. */
1934 delCharAfter(cm: Editor): void;
1935
1936 /** Delete up to the start of the word before the cursor. */
1937 delWordBefore(cm: Editor): void;
1938
1939 /** Delete up to the end of the word after the cursor. */
1940 delWordAfter(cm: Editor): void;
1941
1942 /** Delete to the left of the group before the cursor. */
1943 delGroupBefore(cm: Editor): void;
1944
1945 /** Delete to the start of the group after the cursor. */
1946 delGroupAfter(cm: Editor): void;
1947
1948 /** Auto-indent the current line or selection. */
1949 indentAuto(cm: Editor): void;
1950
1951 /** Indent the current line or selection by one indent unit. */
1952 indentMore(cm: Editor): void;
1953
1954 /** Dedent the current line or selection by one indent unit. */
1955 indentLess(cm: Editor): void;
1956
1957 /** Insert a tab character at the cursor. */
1958 insertTab(cm: Editor): void;
1959
1960 /** Insert the amount of spaces that match the width a tab at the cursor position would have. */
1961 insertSoftTab(cm: Editor): void;
1962
1963 /** If something is selected, indent it by one indent unit. If nothing is selected, insert a tab character. */
1964 defaultTabTab(cm: Editor): void;
1965
1966 /** Swap the characters before and after the cursor. */
1967 transposeChars(cm: Editor): void;
1968
1969 /** Insert a newline and auto-indent the new line. */
1970 newlineAndIndent(cm: Editor): void;
1971
1972 /** Flip the overwrite flag. */
1973 toggleOverwrite(cm: Editor): void;
1974 }
1975
1976 /**
1977 * Commands are parameter-less actions that can be performed on an editor.
1978 * Their main use is for key bindings.
1979 * Commands are defined by adding properties to the CodeMirror.commands object.
1980 */
1981 const commands: CommandActions;
1982
1983 interface MouseSelectionConfiguration {
1984 /**
1985 * The unit by which to select. May be one of the built-in units
1986 * or a function that takes a position and returns a range around
1987 * that, for a custom unit. The default is to return "word" for
1988 * double clicks, "line" for triple clicks, "rectangle" for alt-clicks
1989 * (or, on Chrome OS, meta-shift-clicks), and "single" otherwise.
1990 */
1991 unit?:
1992 | 'char'
1993 | 'word'
1994 | 'line'
1995 | 'rectangle'
1996 | ((cm: Editor, pos: Position) => { from: Position; to: Position }) | undefined;
1997
1998 /**
1999 * Whether to extend the existing selection range or start
2000 * a new one. By default, this is enabled when shift clicking.
2001 */
2002 extend?: boolean | undefined;
2003
2004 /**
2005 * When enabled, this adds a new range to the existing selection,
2006 * rather than replacing it. The default behavior is to enable this
2007 * for command-click on Mac OS, and control-click on other platforms.
2008 */
2009 addNew?: boolean | undefined;
2010
2011 /**
2012 * When the mouse even drags content around inside the editor, this
2013 * controls whether it is copied (false) or moved (true). By default, this
2014 * is enabled by alt-clicking on Mac OS, and ctrl-clicking elsewhere.
2015 */
2016 moveOnDrag?: boolean | undefined;
2017 }
2018}
2019
\No newline at end of file