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