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