UNPKG

105 kBTypeScriptView Raw
1// Type definitions for Ace Ajax.org Cloud9 Editor
2// Project: https://ace.c9.io/
3// Definitions by: Diullei Gomes <https://github.com/Diullei>
4// wafuwafu13 <https://github.com/wafuwafu13>
5// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
6
7declare namespace AceAjax {
8
9 export interface Delta {
10 action: 'insert' | 'remove';
11 start: Position;
12 end: Position;
13 lines: string[];
14 }
15
16 export interface EditorCommand {
17 name?: string | undefined;
18 bindKey?: string | { mac?: string | undefined, win?: string | undefined } | undefined;
19 exec: (editor: Editor, args?: any) => void;
20 readOnly?: boolean | undefined;
21 }
22
23 interface CommandMap {
24 [name: string]: EditorCommand;
25 }
26
27 type execEventHandler = (obj: {
28 editor: Editor,
29 command: EditorCommand,
30 args: any[]
31 }) => void;
32
33 type CommandLike = EditorCommand | ((editor: Editor) => void);
34
35 export interface CommandManager {
36 byName: CommandMap;
37 commands: CommandMap;
38 on(name: 'exec', callback: execEventHandler): Function;
39 on(name: 'afterExec', callback: execEventHandler): Function;
40 once(name: string, callback: Function): void;
41 setDefaultHandler(name: string, callback: Function): void;
42 removeDefaultHandler(name: string, callback: Function): void;
43 on(name: string, callback: Function, capturing?: boolean): Function;
44 addEventListener(name: string, callback: Function, capturing?: boolean): void;
45 off(name: string, callback: Function): void;
46 removeListener(name: string, callback: Function): void;
47 removeEventListener(name: string, callback: Function): void;
48 exec(command: string, editor: Editor, args: any): boolean;
49 toggleRecording(editor: Editor): void;
50 replay(editor: Editor): void;
51 addCommand(command: EditorCommand): void;
52 addCommands(commands: EditorCommand[]): void;
53 removeCommand(command: EditorCommand | string, keepCommand?: boolean): void;
54 removeCommands(command: EditorCommand[]): void;
55 bindKey(key: string | { mac?: string | undefined, win?: string | undefined },
56 command: CommandLike,
57 position?: number): void;
58 bindKeys(keys: {[s: string]: Function}): void;
59 parseKeys(keyPart: string): {key: string, hashId: number};
60 findKeyCommand(hashId: number, keyString: string): string | undefined;
61 handleKeyboard(data: {}, hashId: number, keyString: string, keyCode: string | number): void | {command: string};
62 getStatusText(editor: Editor, data: {}): string;
63 platform: string;
64 }
65
66 export interface Annotation {
67 row?: number | undefined;
68 column?: number | undefined;
69 text: string;
70 type: string;
71 }
72
73 export interface TokenInfo {
74 type: string;
75 value: string;
76 index?: number | undefined;
77 start?: number | undefined;
78 }
79
80 export interface Position {
81 row: number;
82 column: number;
83 }
84
85 export interface KeyboardHandler {
86 handleKeyboard: Function;
87 }
88
89 export interface KeyBinding {
90 setDefaultHandler(kb: KeyboardHandler): void;
91 setKeyboardHandler(kb: KeyboardHandler): void;
92 addKeyboardHandler(kb: KeyboardHandler, pos: number): void;
93 removeKeyboardHandler(kb: KeyboardHandler): boolean;
94 getKeyboardHandler(): KeyboardHandler;
95 onCommandKey(e: any, hashId: number, keyCode: number): boolean;
96 onTextInput(text: string): boolean;
97 }
98
99 export interface TextMode {
100 getTokenizer(): Tokenizer;
101 toggleCommentLines(state: any, session: IEditSession, startRow: number, endRow: number): void;
102 toggleBlockComment(state: any, session: IEditSession, range: Range, cursor: Position): void;
103 getNextLineIndent (state: any, line: string, tab: string): string;
104 checkOutdent(state: any, line: string, input: string): boolean;
105 autoOutdent(state: any, doc: Document, row: number): void;
106 createWorker(session: IEditSession): any;
107 createModeDelegates (mapping: { [key: string]: string }): void;
108 transformAction(state: string, action: string, editor: Editor, session: IEditSession, text: string): any;
109 getKeywords(append?: boolean): Array<string | RegExp>;
110 getCompletions(state: string, session: IEditSession, pos: Position, prefix: string): Completion[];
111 }
112
113 export interface OptionProvider {
114
115 /**
116 * Sets a Configuration Option
117 **/
118 setOption(optionName: string, optionValue: any): void;
119
120 /**
121 * Sets Configuration Options
122 **/
123 setOptions(keyValueTuples: { [key: string]: any }): void;
124
125 /**
126 * Get a Configuration Option
127 **/
128 getOption(name: string): any;
129
130 /**
131 * Get Configuration Options
132 **/
133 getOptions(optionNames?: string[] | { [key: string]: any }): { [key: string]: any };
134 }
135
136 ////////////////
137 /// Ace
138 ////////////////
139
140 /**
141 * The main class required to set up an Ace instance in the browser.
142 **/
143 export interface Ace {
144
145 /**
146 * Provides access to require in packed noconflict mode
147 * @param moduleName
148 **/
149 require(moduleName: string): any;
150
151 /**
152 * Embeds the Ace editor into the DOM, at the element provided by `el`.
153 * @param el Either the id of an element, or the element itself
154 **/
155 edit(el: string): Editor;
156
157 /**
158 * Embeds the Ace editor into the DOM, at the element provided by `el`.
159 * @param el Either the id of an element, or the element itself
160 **/
161 edit(el: HTMLElement): Editor;
162
163 /**
164 * Creates a new [[EditSession]], and returns the associated [[Document]].
165 * @param text {:textParam}
166 * @param mode {:modeParam}
167 **/
168 createEditSession(text: Document, mode: TextMode): IEditSession;
169
170 /**
171 * Creates a new [[EditSession]], and returns the associated [[Document]].
172 * @param text {:textParam}
173 * @param mode {:modeParam}
174 **/
175 createEditSession(text: string, mode: TextMode): IEditSession;
176 }
177
178 ////////////////
179 /// Anchor
180 ////////////////
181
182 /**
183 * Defines the floating pointer in the document. Whenever text is inserted or deleted before the cursor, the position of the cursor is updated.
184 **/
185 export interface Anchor {
186
187 on(event: string, fn: (e: any) => any): void;
188
189 /**
190 * Returns an object identifying the `row` and `column` position of the current anchor.
191 **/
192 getPosition(): Position;
193
194 /**
195 * Returns the current document.
196 **/
197 getDocument(): Document;
198
199 /**
200 * Fires whenever the anchor position changes.
201 * Both of these objects have a `row` and `column` property corresponding to the position.
202 * Events that can trigger this function include [[Anchor.setPosition `setPosition()`]].
203 * @param e An object containing information about the anchor position. It has two properties:
204 * - `old`: An object describing the old Anchor position
205 * - `value`: An object describing the new Anchor position
206 **/
207 onChange(e: any): void;
208
209 /**
210 * Sets the anchor position to the specified row and column. If `noClip` is `true`, the position is not clipped.
211 * @param row The row index to move the anchor to
212 * @param column The column index to move the anchor to
213 * @param noClip Identifies if you want the position to be clipped
214 **/
215 setPosition(row: number, column: number, noClip?: boolean): void;
216
217 /**
218 * When called, the `'change'` event listener is removed.
219 **/
220 detach(): void;
221
222 attach(doc: Document): void;
223 }
224 var Anchor: {
225 /**
226 * Creates a new `Anchor` and associates it with a document.
227 * @param doc The document to associate with the anchor
228 * @param row The starting row position
229 * @param column The starting column position
230 **/
231 new(doc: Document, row: number, column: number): Anchor;
232 }
233
234 ////////////////////////////////
235 /// BackgroundTokenizer
236 ////////////////////////////////
237
238 /**
239 * Tokenizes the current [[Document `Document`]] in the background, and caches the tokenized rows for future use.
240 * If a certain row is changed, everything below that row is re-tokenized.
241 **/
242 export interface BackgroundTokenizer {
243
244 states: any[];
245
246 /**
247 * Sets a new tokenizer for this object.
248 * @param tokenizer The new tokenizer to use
249 **/
250 setTokenizer(tokenizer: Tokenizer): void;
251
252 /**
253 * Sets a new document to associate with this object.
254 * @param doc The new document to associate with
255 **/
256 setDocument(doc: Document): void;
257
258 /**
259 * Emits the `'update'` event. `firstRow` and `lastRow` are used to define the boundaries of the region to be updated.
260 * @param firstRow The starting row region
261 * @param lastRow The final row region
262 **/
263 fireUpdateEvent(firstRow: number, lastRow: number): void;
264
265 /**
266 * Starts tokenizing at the row indicated.
267 * @param startRow The row to start at
268 **/
269 start(startRow: number): void;
270
271 /**
272 * Stops tokenizing.
273 **/
274 stop(): void;
275
276 /**
277 * Gives list of tokens of the row. (tokens are cached)
278 * @param row The row to get tokens at
279 **/
280 getTokens(row: number): TokenInfo[];
281
282 /**
283 * [Returns the state of tokenization at the end of a row.]{: #BackgroundTokenizer.getState}
284 * @param row The row to get state at
285 **/
286 getState(row: number): string;
287 }
288 var BackgroundTokenizer: {
289 /**
290 * Creates a new `BackgroundTokenizer` object.
291 * @param tokenizer The tokenizer to use
292 * @param editor The editor to associate with
293 **/
294 new(tokenizer: Tokenizer, editor: Editor): BackgroundTokenizer;
295 }
296
297 ////////////////
298 /// Document
299 ////////////////
300
301 /**
302 * Contains the text of the document. Document can be attached to several [[EditSession `EditSession`]]s.
303 * At its core, `Document`s are just an array of strings, with each row in the document matching up to the array index.
304 **/
305
306 type NewLineMode = "auto" | "unix" | "windows";
307
308 export interface Document {
309
310 on(event: string, fn: (e: any) => any): void;
311
312 /**
313 * Replaces all the lines in the current `Document` with the value of `text`.
314 * @param text The text to use
315 **/
316 setValue(text: string): void;
317
318 /**
319 * Returns all the lines in the document as a single string, split by the new line character.
320 **/
321 getValue(): string;
322
323 /**
324 * Creates a new `Anchor` to define a floating point in the document.
325 * @param row The row number to use
326 * @param column The column number to use
327 **/
328 createAnchor(row: number, column: number): void;
329
330 /**
331 * Returns the newline character that's being used, depending on the value of `newLineMode`.
332 **/
333 getNewLineCharacter(): string;
334
335 /**
336 * [Sets the new line mode.]{: #Document.setNewLineMode.desc}
337 * @param newLineMode [The newline mode to use; can be either `windows`, `unix`, or `auto`]{: #Document.setNewLineMode.param}
338 **/
339 setNewLineMode(newLineMode: NewLineMode): void;
340
341 /**
342 * [Returns the type of newlines being used; either `windows`, `unix`, or `auto`]{: #Document.getNewLineMode}
343 **/
344 getNewLineMode(): NewLineMode;
345
346 /**
347 * Returns `true` if `text` is a newline character (either `\r\n`, `\r`, or `\n`).
348 * @param text The text to check
349 **/
350 isNewLine(text: string): boolean;
351
352 /**
353 * Returns a verbatim copy of the given line as it is in the document
354 * @param row The row index to retrieve
355 **/
356 getLine(row: number): string;
357
358 /**
359 * Returns an array of strings of the rows between `firstRow` and `lastRow`. This function is inclusive of `lastRow`.
360 * @param firstRow The first row index to retrieve
361 * @param lastRow The final row index to retrieve
362 **/
363 getLines(firstRow: number, lastRow: number): string[];
364
365 /**
366 * Returns all lines in the document as string array. Warning: The caller should not modify this array!
367 **/
368 getAllLines(): string[];
369
370 /**
371 * Returns the number of rows in the document.
372 **/
373 getLength(): number;
374
375 /**
376 * [Given a range within the document, this function returns all the text within that range as a single string.]{: #Document.getTextRange.desc}
377 * @param range The range to work with
378 **/
379 getTextRange(range: Range): string;
380
381 getLinesForRange(range: Range): string[];
382
383 /**
384 * Inserts a block of `text` and the indicated `position`.
385 * @param position The position to start inserting at
386 * @param text A chunk of text to insert
387 **/
388 insert(position: Position, text: string): Position;
389
390 /**
391 * @deprecated Use the insertFullLines method instead.
392 */
393 insertLines(row: number, lines: string[]): Position;
394
395 /**
396 * Inserts the elements in `lines` into the document as full lines (does not merge with existing line), starting at the row index given by `row`. This method also triggers the `"change"` event.
397 * @param {Number} row The index of the row to insert at
398 * @param {Array} lines An array of strings
399 * @returns {Object} Contains the final row and column, like this:
400 * ```
401 * {row: endRow, column: 0}
402 * ```
403 * If `lines` is empty, this function returns an object containing the current row, and column, like this:
404 * ```
405 * {row: row, column: 0}
406 * ```
407 *
408 **/
409 insertFullLines(row: number, lines: string[]): void;
410
411 /**
412 * @deprecated Use insertMergedLines(position, ['', '']) instead.
413 */
414 insertNewLine(position: Position): Position;
415
416 /**
417 * Inserts the elements in `lines` into the document, starting at the position index given by `row`. This method also triggers the `"change"` event.
418 * @param {Number} row The index of the row to insert at
419 * @param {Array} lines An array of strings
420 * @returns {Object} Contains the final row and column, like this:
421 * ```
422 * {row: endRow, column: 0}
423 * ```
424 * If `lines` is empty, this function returns an object containing the current row, and column, like this:
425 * ```
426 * {row: row, column: 0}
427 * ```
428 *
429 **/
430 insertMergedLines(row: number, lines: string[]): Position;
431
432 /**
433 * Inserts `text` into the `position` at the current row. This method also triggers the `'change'` event.
434 * @param position The position to insert at
435 * @param text A chunk of text
436 **/
437 insertInLine(position: Position, text: string): Position;
438
439 clippedPos(row: number, column: number): Position;
440 clonePos(pos: Position): Position;
441 pos(row: number, column: number): Position;
442
443 /**
444 * Removes the `range` from the document.
445 * @param range A specified Range to remove
446 **/
447 remove(range: Range): Position;
448
449 /**
450 * Removes the specified columns from the `row`. This method also triggers the `'change'` event.
451 * @param row The row to remove from
452 * @param startColumn The column to start removing at
453 * @param endColumn The column to stop removing at
454 **/
455 removeInLine(row: number, startColumn: number, endColumn: number): Position;
456
457 /**
458 * @deprecated Use the removeFullLines method instead.
459 */
460 removeLines(firstRow: number, lastRow: number): string[];
461
462 /**
463 * Removes a range of full lines. This method also triggers the `"change"` event.
464 * @param {Number} firstRow The first row to be removed
465 * @param {Number} lastRow The last row to be removed
466 * @returns {[String]} Returns all the removed lines.
467 *
468 **/
469 removeFullLines(firstRow: number, lastRow: number): string[];
470
471 /**
472 * Removes the new line between `row` and the row immediately following it. This method also triggers the `'change'` event.
473 * @param row The row to check
474 **/
475 removeNewLine(row: number): void;
476
477 /**
478 * Replaces a range in the document with the new `text`.
479 * @param range A specified Range to replace
480 * @param text The new text to use as a replacement
481 **/
482 replace(range: Range, text: string): Position;
483
484 /**
485 * Applies all the changes previously accumulated. These can be either `'includeText'`, `'insertLines'`, `'removeText'`, and `'removeLines'`.
486 **/
487 applyDeltas(deltas: Delta[]): void;
488
489 /**
490 * Reverts any changes previously applied. These can be either `'includeText'`, `'insertLines'`, `'removeText'`, and `'removeLines'`.
491 **/
492 revertDeltas(deltas: Delta[]): void;
493
494 /**
495 * Converts an index position in a document to a `{row, column}` object.
496 * Index refers to the "absolute position" of a character in the document. For example:
497 * ```javascript
498 * var x = 0; // 10 characters, plus one for newline
499 * var y = -1;
500 * ```
501 * Here, `y` is an index 15: 11 characters for the first row, and 5 characters until `y` in the second.
502 * @param index An index to convert
503 * @param startRow=0 The row from which to start the conversion
504 **/
505 indexToPosition(index: number, startRow: number): Position;
506
507 /**
508 * Converts the `{row, column}` position in a document to the character's index.
509 * Index refers to the "absolute position" of a character in the document. For example:
510 * ```javascript
511 * var x = 0; // 10 characters, plus one for newline
512 * var y = -1;
513 * ```
514 * Here, `y` is an index 15: 11 characters for the first row, and 5 characters until `y` in the second.
515 * @param pos The `{row, column}` to convert
516 * @param startRow=0 The row from which to start the conversion
517 **/
518 positionToIndex(pos: Position, startRow?: number): number;
519 }
520 var Document: {
521 /**
522 * Creates a new `Document`. If `text` is included, the `Document` contains those strings; otherwise, it's empty.
523 * @param text The starting text
524 **/
525 new(text?: string): Document;
526 /**
527 * Creates a new `Document`. If `text` is included, the `Document` contains those strings; otherwise, it's empty.
528 * @param text The starting text
529 **/
530 new(text?: string[]): Document;
531 }
532
533 ////////////////////////////////
534 /// EditSession
535 ////////////////////////////////
536
537 /**
538 * Stores all the data about [[Editor `Editor`]] state providing easy way to change editors state.
539 * `EditSession` can be attached to only one [[Document `Document`]]. Same `Document` can be attached to several `EditSession`s.
540 **/
541 export interface IEditSession extends OptionProvider {
542
543 selection: Selection;
544
545 bgTokenizer: BackgroundTokenizer;
546
547 doc: Document;
548
549 on(event: string, fn: (e: any) => any): void;
550
551 findMatchingBracket(position: Position): void;
552
553 addFold(text: string, range: Range): void;
554
555 getFoldAt(row: number, column: number): any;
556
557 removeFold(arg: any): void;
558
559 expandFold(arg: any): void;
560
561 foldAll(startRow?: number, endRow?: number, depth?: number): void
562
563 unfold(arg1: any, arg2: boolean): void;
564
565 screenToDocumentColumn(row: number, column: number): void;
566
567 getFoldDisplayLine(foldLine: any, docRow: number, docColumn: number): any;
568
569 getFoldsInRange(range: Range): any;
570
571 highlight(text: string): void;
572
573
574 /**
575 * Highlight lines from `startRow` to `EndRow`.
576 * @param startRow Define the start line of the highlight
577 * @param endRow Define the end line of the highlight
578 * @param clazz Set the CSS class for the marker
579 * @param inFront Set to `true` to establish a front marker
580 **/
581 highlightLines(startRow:number, endRow: number, clazz: string, inFront: boolean): Range;
582
583 /**
584 * Sets the `EditSession` to point to a new `Document`. If a `BackgroundTokenizer` exists, it also points to `doc`.
585 * @param doc The new `Document` to use
586 **/
587 setDocument(doc: Document): void;
588
589 /**
590 * Returns the `Document` associated with this session.
591 **/
592 getDocument(): Document;
593
594 /**
595 * undefined
596 * @param row The row to work with
597 **/
598 $resetRowCache(row: number): void;
599
600 /**
601 * Sets the session text.
602 * @param text The new text to place
603 **/
604 setValue(text: string): void;
605
606 setMode(mode: string): void;
607
608 /**
609 * Returns the current [[Document `Document`]] as a string.
610 **/
611 getValue(): string;
612
613 /**
614 * Returns the string of the current selection.
615 **/
616 getSelection(): Selection;
617
618 /**
619 * {:BackgroundTokenizer.getState}
620 * @param row The row to start at
621 **/
622 getState(row: number): string;
623
624 /**
625 * Starts tokenizing at the row indicated. Returns a list of objects of the tokenized rows.
626 * @param row The row to start at
627 **/
628 getTokens(row: number): TokenInfo[];
629
630 /**
631 * Returns an object indicating the token at the current row. The object has two properties: `index` and `start`.
632 * @param row The row number to retrieve from
633 * @param column The column number to retrieve from
634 **/
635 getTokenAt(row: number, column: number): TokenInfo|null;
636
637 /**
638 * Sets the undo manager.
639 * @param undoManager The new undo manager
640 **/
641 setUndoManager(undoManager: UndoManager): void;
642
643 /**
644 * Returns the current undo manager.
645 **/
646 getUndoManager(): UndoManager;
647
648 /**
649 * Returns the current value for tabs. If the user is using soft tabs, this will be a series of spaces (defined by [[EditSession.getTabSize `getTabSize()`]]): void; otherwise it's simply `'\t'`.
650 **/
651 getTabString(): string;
652
653 /**
654 * Pass `true` to enable the use of soft tabs. Soft tabs means you're using spaces instead of the tab character (`'\t'`).
655 * @param useSoftTabs Value indicating whether or not to use soft tabs
656 **/
657 setUseSoftTabs(useSoftTabs: boolean): void;
658
659 /**
660 * Returns `true` if soft tabs are being used, `false` otherwise.
661 **/
662 getUseSoftTabs(): boolean;
663
664 /**
665 * Set the number of spaces that define a soft tab; for example, passing in `4` transforms the soft tabs to be equivalent to four spaces. This function also emits the `changeTabSize` event.
666 * @param tabSize The new tab size
667 **/
668 setTabSize(tabSize: number): void;
669
670 /**
671 * Returns the current tab size.
672 **/
673 getTabSize(): number;
674
675 /**
676 * Returns `true` if the character at the position is a soft tab.
677 * @param position The position to check
678 **/
679 isTabStop(position: any): boolean;
680
681 /**
682 * Pass in `true` to enable overwrites in your session, or `false` to disable.
683 * If overwrites is enabled, any text you enter will type over any text after it. If the value of `overwrite` changes, this function also emites the `changeOverwrite` event.
684 * @param overwrite Defines wheter or not to set overwrites
685 **/
686 setOverwrite(overwrite: boolean): void;
687
688 /**
689 * Returns `true` if overwrites are enabled; `false` otherwise.
690 **/
691 getOverwrite(): boolean;
692
693 /**
694 * Sets the value of overwrite to the opposite of whatever it currently is.
695 **/
696 toggleOverwrite(): void;
697
698 /**
699 * Adds `className` to the `row`, to be used for CSS stylings and whatnot.
700 * @param row The row number
701 * @param className The class to add
702 **/
703 addGutterDecoration(row: number, className: string): void;
704
705 /**
706 * Removes `className` from the `row`.
707 * @param row The row number
708 * @param className The class to add
709 **/
710 removeGutterDecoration(row: number, className: string): void;
711
712 /**
713 * Returns an array of numbers, indicating which rows have breakpoints.
714 **/
715 getBreakpoints(): number[];
716
717 /**
718 * Sets a breakpoint on every row number given by `rows`. This function also emites the `'changeBreakpoint'` event.
719 * @param rows An array of row indices
720 **/
721 setBreakpoints(rows: any[]): void;
722
723 /**
724 * Removes all breakpoints on the rows. This function also emites the `'changeBreakpoint'` event.
725 **/
726 clearBreakpoints(): void;
727
728 /**
729 * Sets a breakpoint on the row number given by `rows`. This function also emites the `'changeBreakpoint'` event.
730 * @param row A row index
731 * @param className Class of the breakpoint
732 **/
733 setBreakpoint(row: number, className: string): void;
734
735 /**
736 * Removes a breakpoint on the row number given by `rows`. This function also emites the `'changeBreakpoint'` event.
737 * @param row A row index
738 **/
739 clearBreakpoint(row: number): void;
740
741 /**
742 * Adds a new marker to the given `Range`. If `inFront` is `true`, a front marker is defined, and the `'changeFrontMarker'` event fires; otherwise, the `'changeBackMarker'` event fires.
743 * @param range Define the range of the marker
744 * @param clazz Set the CSS class for the marker
745 * @param type Identify the type of the marker
746 * @param inFront Set to `true` to establish a front marker
747 **/
748 addMarker(range: Range, clazz: string, type: Function, inFront: boolean): number;
749
750 /**
751 * Adds a new marker to the given `Range`. If `inFront` is `true`, a front marker is defined, and the `'changeFrontMarker'` event fires; otherwise, the `'changeBackMarker'` event fires.
752 * @param range Define the range of the marker
753 * @param clazz Set the CSS class for the marker
754 * @param type Identify the type of the marker
755 * @param inFront Set to `true` to establish a front marker
756 **/
757 addMarker(range: Range, clazz: string, type: string, inFront: boolean): number;
758
759 /**
760 * Adds a dynamic marker to the session.
761 * @param marker object with update method
762 * @param inFront Set to `true` to establish a front marker
763 **/
764 addDynamicMarker(marker: any, inFront: boolean): void;
765
766 /**
767 * Removes the marker with the specified ID. If this marker was in front, the `'changeFrontMarker'` event is emitted. If the marker was in the back, the `'changeBackMarker'` event is emitted.
768 * @param markerId A number representing a marker
769 **/
770 removeMarker(markerId: number): void;
771
772 /**
773 * Returns an array containing the IDs of all the markers, either front or back.
774 * @param inFront If `true`, indicates you only want front markers; `false` indicates only back markers
775 **/
776 getMarkers(inFront: boolean): any[];
777
778 /**
779 * Sets annotations for the `EditSession`. This functions emits the `'changeAnnotation'` event.
780 * @param annotations A list of annotations
781 **/
782 setAnnotations(annotations: Annotation[]): void;
783
784 /**
785 * Returns the annotations for the `EditSession`.
786 **/
787 getAnnotations(): any;
788
789 /**
790 * Clears all the annotations for this session. This function also triggers the `'changeAnnotation'` event.
791 **/
792 clearAnnotations(): void;
793
794 /**
795 * If `text` contains either the newline (`\n`) or carriage-return ('\r') characters, `$autoNewLine` stores that value.
796 * @param text A block of text
797 **/
798 $detectNewLine(text: string): void;
799
800 /**
801 * Given a starting row and column, this method returns the `Range` of the first word boundary it finds.
802 * @param row The row to start at
803 * @param column The column to start at
804 **/
805 getWordRange(row: number, column: number): Range;
806
807 /**
808 * Gets the range of a word, including its right whitespace.
809 * @param row The row number to start from
810 * @param column The column number to start from
811 **/
812 getAWordRange(row: number, column: number): any;
813
814 /**
815 * {:Document.setNewLineMode.desc}
816 * @param newLineMode {:Document.setNewLineMode.param}
817 **/
818 setNewLineMode(newLineMode: string): void;
819
820 /**
821 * Returns the current new line mode.
822 **/
823 getNewLineMode(): string;
824
825 /**
826 * Identifies if you want to use a worker for the `EditSession`.
827 * @param useWorker Set to `true` to use a worker
828 **/
829 setUseWorker(useWorker: boolean): void;
830
831 /**
832 * Returns `true` if workers are being used.
833 **/
834 getUseWorker(): boolean;
835
836 /**
837 * Reloads all the tokens on the current session. This function calls [[BackgroundTokenizer.start `BackgroundTokenizer.start ()`]] to all the rows; it also emits the `'tokenizerUpdate'` event.
838 **/
839 onReloadTokenizer(): void;
840
841 /**
842 * Sets a new text mode for the `EditSession`. This method also emits the `'changeMode'` event. If a [[BackgroundTokenizer `BackgroundTokenizer`]] is set, the `'tokenizerUpdate'` event is also emitted.
843 * @param mode Set a new text mode
844 **/
845 $mode(mode: TextMode): void;
846
847 /**
848 * Returns the current text mode.
849 **/
850 getMode(): TextMode;
851
852 /**
853 * This function sets the scroll top value. It also emits the `'changeScrollTop'` event.
854 * @param scrollTop The new scroll top value
855 **/
856 setScrollTop(scrollTop: number): void;
857
858 /**
859 * [Returns the value of the distance between the top of the editor and the topmost part of the visible content.]{: #EditSession.getScrollTop}
860 **/
861 getScrollTop(): number;
862
863 /**
864 * [Sets the value of the distance between the left of the editor and the leftmost part of the visible content.]{: #EditSession.setScrollLeft}
865 * @param scrollLeft The new scroll left value
866 **/
867 setScrollLeft(scrollLeft: number): void;
868
869 /**
870 * [Returns the value of the distance between the left of the editor and the leftmost part of the visible content.]{: #EditSession.getScrollLeft}
871 **/
872 getScrollLeft(): number;
873
874 /**
875 * Returns the width of the screen.
876 **/
877 getScreenWidth(): number;
878
879 /**
880 * Returns a verbatim copy of the given line as it is in the document
881 * @param row The row to retrieve from
882 **/
883 getLine(row: number): string;
884
885 /**
886 * Returns an array of strings of the rows between `firstRow` and `lastRow`. This function is inclusive of `lastRow`.
887 * @param firstRow The first row index to retrieve
888 * @param lastRow The final row index to retrieve
889 **/
890 getLines(firstRow: number, lastRow: number): string[];
891
892 /**
893 * Returns the number of rows in the document.
894 **/
895 getLength(): number;
896
897 /**
898 * {:Document.getTextRange.desc}
899 * @param range The range to work with
900 **/
901 getTextRange(range: Range): string;
902
903 /**
904 * Inserts a block of `text` and the indicated `position`.
905 * @param position The position {row, column} to start inserting at
906 * @param text A chunk of text to insert
907 **/
908 insert(position: Position, text: string): any;
909
910 /**
911 * Removes the `range` from the document.
912 * @param range A specified Range to remove
913 **/
914 remove(range: Range): any;
915
916 /**
917 * Reverts previous changes to your document.
918 * @param deltas An array of previous changes
919 * @param dontSelect [If `true`, doesn't select the range of where the change occured]{: #dontSelect}
920 **/
921 undoChanges(deltas: any[], dontSelect: boolean): Range;
922
923 /**
924 * Re-implements a previously undone change to your document.
925 * @param deltas An array of previous changes
926 * @param dontSelect {:dontSelect}
927 **/
928 redoChanges(deltas: any[], dontSelect: boolean): Range;
929
930 /**
931 * Enables or disables highlighting of the range where an undo occured.
932 * @param enable If `true`, selects the range of the reinserted change
933 **/
934 setUndoSelect(enable: boolean): void;
935
936 /**
937 * Replaces a range in the document with the new `text`.
938 * @param range A specified Range to replace
939 * @param text The new text to use as a replacement
940 **/
941 replace(range: Range, text: string): any;
942
943 /**
944 * Moves a range of text from the given range to the given position. `toPosition` is an object that looks like this:
945 * ```json
946 * { row: newRowLocation, column: newColumnLocation }
947 * ```
948 * @param fromRange The range of text you want moved within the document
949 * @param toPosition The location (row and column) where you want to move the text to
950 **/
951 moveText(fromRange: Range, toPosition: any): Range;
952
953 /**
954 * Indents all the rows, from `startRow` to `endRow` (inclusive), by prefixing each row with the token in `indentString`.
955 * If `indentString` contains the `'\t'` character, it's replaced by whatever is defined by [[EditSession.getTabString `getTabString()`]].
956 * @param startRow Starting row
957 * @param endRow Ending row
958 * @param indentString The indent token
959 **/
960 indentRows(startRow: number, endRow: number, indentString: string): void;
961
962 /**
963 * Outdents all the rows defined by the `start` and `end` properties of `range`.
964 * @param range A range of rows
965 **/
966 outdentRows(range: Range): void;
967
968 /**
969 * Shifts all the lines in the document up one, starting from `firstRow` and ending at `lastRow`.
970 * @param firstRow The starting row to move up
971 * @param lastRow The final row to move up
972 **/
973 moveLinesUp(firstRow: number, lastRow: number): number;
974
975 /**
976 * Shifts all the lines in the document down one, starting from `firstRow` and ending at `lastRow`.
977 * @param firstRow The starting row to move down
978 * @param lastRow The final row to move down
979 **/
980 moveLinesDown(firstRow: number, lastRow: number): number;
981
982 /**
983 * Duplicates all the text between `firstRow` and `lastRow`.
984 * @param firstRow The starting row to duplicate
985 * @param lastRow The final row to duplicate
986 **/
987 duplicateLines(firstRow: number, lastRow: number): number;
988
989 /**
990 * Sets whether or not line wrapping is enabled. If `useWrapMode` is different than the current value, the `'changeWrapMode'` event is emitted.
991 * @param useWrapMode Enable (or disable) wrap mode
992 **/
993 setUseWrapMode(useWrapMode: boolean): void;
994
995 /**
996 * Returns `true` if wrap mode is being used; `false` otherwise.
997 **/
998 getUseWrapMode(): boolean;
999
1000 /**
1001 * Sets the boundaries of wrap. Either value can be `null` to have an unconstrained wrap, or, they can be the same number to pin the limit. If the wrap limits for `min` or `max` are different, this method also emits the `'changeWrapMode'` event.
1002 * @param min The minimum wrap value (the left side wrap)
1003 * @param max The maximum wrap value (the right side wrap)
1004 **/
1005 setWrapLimitRange(min: number, max: number): void;
1006
1007 /**
1008 * This should generally only be called by the renderer when a resize is detected.
1009 * @param desiredLimit The new wrap limit
1010 **/
1011 adjustWrapLimit(desiredLimit: number): boolean;
1012
1013 /**
1014 * Returns the value of wrap limit.
1015 **/
1016 getWrapLimit(): number;
1017
1018 /**
1019 * Returns an object that defines the minimum and maximum of the wrap limit; it looks something like this:
1020 * { min: wrapLimitRange_min, max: wrapLimitRange_max }
1021 **/
1022 getWrapLimitRange(): any;
1023
1024 /**
1025 * Given a string, returns an array of the display characters, including tabs and spaces.
1026 * @param str The string to check
1027 * @param offset The value to start at
1028 **/
1029 $getDisplayTokens(str: string, offset: number): void;
1030
1031 /**
1032 * Calculates the width of the string `str` on the screen while assuming that the string starts at the first column on the screen.
1033 * @param str The string to calculate the screen width of
1034 * @param maxScreenColumn
1035 * @param screenColumn
1036 **/
1037 $getStringScreenWidth(str: string, maxScreenColumn: number, screenColumn: number): number[];
1038
1039 /**
1040 * Returns number of screenrows in a wrapped line.
1041 * @param row The row number to check
1042 **/
1043 getRowLength(row: number): number;
1044
1045 /**
1046 * Returns the position (on screen) for the last character in the provided screen row.
1047 * @param screenRow The screen row to check
1048 **/
1049 getScreenLastRowColumn(screenRow: number): number;
1050
1051 /**
1052 * For the given document row and column, this returns the column position of the last screen row.
1053 * @param docRow
1054 * @param docColumn
1055 **/
1056 getDocumentLastRowColumn(docRow: number, docColumn: number): number;
1057
1058 /**
1059 * For the given document row and column, this returns the document position of the last row.
1060 * @param docRow
1061 * @param docColumn
1062 **/
1063 getDocumentLastRowColumnPosition(docRow: number, docColumn: number): number;
1064
1065 /**
1066 * For the given row, this returns the split data.
1067 **/
1068 getRowSplitData(): string;
1069
1070 /**
1071 * The distance to the next tab stop at the specified screen column.
1072 * @param screenColumn The screen column to check
1073 **/
1074 getScreenTabSize(screenColumn: number): number;
1075
1076 /**
1077 * Converts characters coordinates on the screen to characters coordinates within the document. [This takes into account code folding, word wrap, tab size, and any other visual modifications.]{: #conversionConsiderations}
1078 * @param screenRow The screen row to check
1079 * @param screenColumn The screen column to check
1080 **/
1081 screenToDocumentPosition(screenRow: number, screenColumn: number): any;
1082
1083 /**
1084 * Converts document coordinates to screen coordinates. {:conversionConsiderations}
1085 * @param docRow The document row to check
1086 * @param docColumn The document column to check
1087 **/
1088 documentToScreenPosition(docRow: number, docColumn: number): any;
1089
1090 /**
1091 * For the given document row and column, returns the screen column.
1092 * @param row
1093 * @param docColumn
1094 **/
1095 documentToScreenColumn(row: number, docColumn: number): number;
1096
1097 /**
1098 * For the given document row and column, returns the screen row.
1099 * @param docRow
1100 * @param docColumn
1101 **/
1102 documentToScreenRow(docRow: number, docColumn: number): void;
1103
1104 /**
1105 * Returns the length of the screen.
1106 **/
1107 getScreenLength(): number;
1108 }
1109 var EditSession: {
1110 /**
1111 * Sets up a new `EditSession` and associates it with the given `Document` and `TextMode`.
1112 * @param text [If `text` is a `Document`, it associates the `EditSession` with it. Otherwise, a new `Document` is created, with the initial text]{: #textParam}
1113 * @param mode [The inital language mode to use for the document]{: #modeParam}
1114 **/
1115 new(text: string, mode?: TextMode): IEditSession;
1116
1117 new(content: string, mode?: string): IEditSession;
1118
1119 new (text: string[], mode?: string): IEditSession;
1120 }
1121
1122 ////////////////////////////////
1123 /// Editor
1124 ////////////////////////////////
1125
1126 /**
1127 * The main entry point into the Ace functionality.
1128 * The `Editor` manages the [[EditSession]] (which manages [[Document]]s), as well as the [[VirtualRenderer]], which draws everything to the screen.
1129 * Event sessions dealing with the mouse and keyboard are bubbled up from `Document` to the `Editor`, which decides what to do with them.
1130 **/
1131 export interface Editor extends OptionProvider {
1132
1133 on(ev: string, callback: (e: any) => any): void;
1134
1135 addEventListener(ev: 'change', callback: (ev: EditorChangeEvent) => any): void;
1136 addEventListener(ev: string, callback: Function): void;
1137
1138 off(ev: string, callback: Function): void;
1139
1140 removeListener(ev: string, callback: Function): void;
1141
1142 removeEventListener(ev: string, callback: Function): void;
1143
1144 inMultiSelectMode: boolean;
1145
1146 selectMoreLines(n: number): void;
1147
1148 onTextInput(text: string): void;
1149
1150 onCommandKey(e: any, hashId: number, keyCode: number): void;
1151
1152 commands: CommandManager;
1153
1154 session: IEditSession;
1155
1156 selection: Selection;
1157
1158 renderer: VirtualRenderer;
1159
1160 keyBinding: KeyBinding;
1161
1162 container: HTMLElement;
1163
1164 onSelectionChange(e: any): void;
1165
1166 onChangeMode(e?: any): void;
1167
1168 execCommand(command:string, args?: any): void;
1169
1170 /**
1171 * Get rid of console warning by setting this to Infinity
1172 **/
1173 $blockScrolling:number;
1174
1175 /**
1176 * Sets a new key handler, such as "vim" or "windows".
1177 * @param keyboardHandler The new key handler
1178 **/
1179 setKeyboardHandler(keyboardHandler: string): void;
1180
1181 /**
1182 * Returns the keyboard handler, such as "vim" or "windows".
1183 **/
1184 getKeyboardHandler(): string;
1185
1186 /**
1187 * Sets a new editsession to use. This method also emits the `'changeSession'` event.
1188 * @param session The new session to use
1189 **/
1190 setSession(session: IEditSession): void;
1191
1192 /**
1193 * Returns the current session being used.
1194 **/
1195 getSession(): IEditSession;
1196
1197 /**
1198 * Sets the current document to `val`.
1199 * @param val The new value to set for the document
1200 * @param cursorPos Where to set the new value. `undefined` or 0 is selectAll, -1 is at the document start, and 1 is at the end
1201 **/
1202 setValue(val: string, cursorPos?: number): string;
1203
1204 /**
1205 * Returns the current session's content.
1206 **/
1207 getValue(): string;
1208
1209 /**
1210 * Returns the currently highlighted selection.
1211 **/
1212 getSelection(): Selection;
1213
1214 /**
1215 * {:VirtualRenderer.onResize}
1216 * @param force If `true`, recomputes the size, even if the height and width haven't changed
1217 **/
1218 resize(force?: boolean): void;
1219
1220 /**
1221 * {:VirtualRenderer.setTheme}
1222 * @param theme The path to a theme
1223 **/
1224 setTheme(theme: string): void;
1225
1226 /**
1227 * {:VirtualRenderer.getTheme}
1228 **/
1229 getTheme(): string;
1230
1231 /**
1232 * {:VirtualRenderer.setStyle}
1233 * @param style A class name
1234 **/
1235 setStyle(style: string): void;
1236
1237 /**
1238 * {:VirtualRenderer.unsetStyle}
1239 **/
1240 unsetStyle(): void;
1241
1242 /**
1243 * Set a new font size (in pixels) for the editor text.
1244 * @param size A font size ( _e.g._ "12px")
1245 **/
1246 setFontSize(size: string): void;
1247
1248 /**
1249 * Brings the current `textInput` into focus.
1250 **/
1251 focus(): void;
1252
1253 /**
1254 * Returns `true` if the current `textInput` is in focus.
1255 **/
1256 isFocused(): boolean;
1257
1258 /**
1259 * Blurs the current `textInput`.
1260 **/
1261 blur(): void;
1262
1263 /**
1264 * Emitted once the editor comes into focus.
1265 **/
1266 onFocus(): void;
1267
1268 /**
1269 * Emitted once the editor has been blurred.
1270 **/
1271 onBlur(): void;
1272
1273 /**
1274 * Emitted whenever the document is changed.
1275 * @param e Contains a single property, `data`, which has the delta of changes
1276 **/
1277 onDocumentChange(e: any): void;
1278
1279 /**
1280 * Emitted when the selection changes.
1281 **/
1282 onCursorChange(): void;
1283
1284 /**
1285 * Returns the string of text currently highlighted.
1286 **/
1287 getCopyText(): string;
1288
1289 /**
1290 * Called whenever a text "copy" happens.
1291 **/
1292 onCopy(): void;
1293
1294 /**
1295 * Called whenever a text "cut" happens.
1296 **/
1297 onCut(): void;
1298
1299 /**
1300 * Called whenever a text "paste" happens.
1301 * @param text The pasted text
1302 **/
1303 onPaste(text: string): void;
1304
1305 /**
1306 * Inserts `text` into wherever the cursor is pointing.
1307 * @param text The new text to add
1308 **/
1309 insert(text: string): void;
1310
1311 /**
1312 * Pass in `true` to enable overwrites in your session, or `false` to disable. If overwrites is enabled, any text you enter will type over any text after it. If the value of `overwrite` changes, this function also emites the `changeOverwrite` event.
1313 * @param overwrite Defines wheter or not to set overwrites
1314 **/
1315 setOverwrite(overwrite: boolean): void;
1316
1317 /**
1318 * Returns `true` if overwrites are enabled; `false` otherwise.
1319 **/
1320 getOverwrite(): boolean;
1321
1322 /**
1323 * Sets the value of overwrite to the opposite of whatever it currently is.
1324 **/
1325 toggleOverwrite(): void;
1326
1327 /**
1328 * Sets how fast the mouse scrolling should do.
1329 * @param speed A value indicating the new speed (in milliseconds)
1330 **/
1331 setScrollSpeed(speed: number): void;
1332
1333 /**
1334 * Returns the value indicating how fast the mouse scroll speed is (in milliseconds).
1335 **/
1336 getScrollSpeed(): number;
1337
1338 /**
1339 * Sets the delay (in milliseconds) of the mouse drag.
1340 * @param dragDelay A value indicating the new delay
1341 **/
1342 setDragDelay(dragDelay: number): void;
1343
1344 /**
1345 * Returns the current mouse drag delay.
1346 **/
1347 getDragDelay(): number;
1348
1349 /**
1350 * Indicates how selections should occur.
1351 * By default, selections are set to "line". There are no other styles at the moment,
1352 * although this code change in the future.
1353 * This function also emits the `'changeSelectionStyle'` event.
1354 * @param style The new selection style
1355 **/
1356 setSelectionStyle(style: string): void;
1357
1358 /**
1359 * Returns the current selection style.
1360 **/
1361 getSelectionStyle(): string;
1362
1363 /**
1364 * Determines whether or not the current line should be highlighted.
1365 * @param shouldHighlight Set to `true` to highlight the current line
1366 **/
1367 setHighlightActiveLine(shouldHighlight: boolean): void;
1368
1369 /**
1370 * Returns `true` if current lines are always highlighted.
1371 **/
1372 getHighlightActiveLine(): boolean;
1373
1374 /**
1375 * Determines if the currently selected word should be highlighted.
1376 * @param shouldHighlight Set to `true` to highlight the currently selected word
1377 **/
1378 setHighlightSelectedWord(shouldHighlight: boolean): void;
1379
1380 /**
1381 * Returns `true` if currently highlighted words are to be highlighted.
1382 **/
1383 getHighlightSelectedWord(): boolean;
1384
1385 /**
1386 * If `showInvisibiles` is set to `true`, invisible characters&mdash;like spaces or new lines&mdash;are show in the editor.
1387 * @param showInvisibles Specifies whether or not to show invisible characters
1388 **/
1389 setShowInvisibles(showInvisibles: boolean): void;
1390
1391 /**
1392 * Returns `true` if invisible characters are being shown.
1393 **/
1394 getShowInvisibles(): boolean;
1395
1396 /**
1397 * If `showPrintMargin` is set to `true`, the print margin is shown in the editor.
1398 * @param showPrintMargin Specifies whether or not to show the print margin
1399 **/
1400 setShowPrintMargin(showPrintMargin: boolean): void;
1401
1402 /**
1403 * Returns `true` if the print margin is being shown.
1404 **/
1405 getShowPrintMargin(): boolean;
1406
1407 /**
1408 * Sets the column defining where the print margin should be.
1409 * @param showPrintMargin Specifies the new print margin
1410 **/
1411 setPrintMarginColumn(showPrintMargin: number): void;
1412
1413 /**
1414 * Returns the column number of where the print margin is.
1415 **/
1416 getPrintMarginColumn(): number;
1417
1418 /**
1419 * If `readOnly` is true, then the editor is set to read-only mode, and none of the content can change.
1420 * @param readOnly Specifies whether the editor can be modified or not
1421 **/
1422 setReadOnly(readOnly: boolean): void;
1423
1424 /**
1425 * Returns `true` if the editor is set to read-only mode.
1426 **/
1427 getReadOnly(): boolean;
1428
1429 /**
1430 * Specifies whether to use behaviors or not. ["Behaviors" in this case is the auto-pairing of special characters, like quotation marks, parenthesis, or brackets.]{: #BehaviorsDef}
1431 * @param enabled Enables or disables behaviors
1432 **/
1433 setBehavioursEnabled(enabled: boolean): void;
1434
1435 /**
1436 * Returns `true` if the behaviors are currently enabled. {:BehaviorsDef}
1437 **/
1438 getBehavioursEnabled(): boolean;
1439
1440 /**
1441 * Specifies whether to use wrapping behaviors or not, i.e. automatically wrapping the selection with characters such as brackets
1442 * when such a character is typed in.
1443 * @param enabled Enables or disables wrapping behaviors
1444 **/
1445 setWrapBehavioursEnabled(enabled: boolean): void;
1446
1447 /**
1448 * Returns `true` if the wrapping behaviors are currently enabled.
1449 **/
1450 getWrapBehavioursEnabled(): void;
1451
1452 /**
1453 * Indicates whether the fold widgets are shown or not.
1454 * @param show Specifies whether the fold widgets are shown
1455 **/
1456 setShowFoldWidgets(show: boolean): void;
1457
1458 /**
1459 * Returns `true` if the fold widgets are shown.
1460 **/
1461 getShowFoldWidgets(): void;
1462
1463 /**
1464 * Removes words of text from the editor. A "word" is defined as a string of characters bookended by whitespace.
1465 * @param dir The direction of the deletion to occur, either "left" or "right"
1466 **/
1467 remove(dir: string): void;
1468
1469 /**
1470 * Removes the word directly to the right of the current selection.
1471 **/
1472 removeWordRight(): void;
1473
1474 /**
1475 * Removes the word directly to the left of the current selection.
1476 **/
1477 removeWordLeft(): void;
1478
1479 /**
1480 * Removes all the words to the left of the current selection, until the start of the line.
1481 **/
1482 removeToLineStart(): void;
1483
1484 /**
1485 * Removes all the words to the right of the current selection, until the end of the line.
1486 **/
1487 removeToLineEnd(): void;
1488
1489 /**
1490 * Splits the line at the current selection (by inserting an `'\n'`).
1491 **/
1492 splitLine(): void;
1493
1494 /**
1495 * Transposes current line.
1496 **/
1497 transposeLetters(): void;
1498
1499 /**
1500 * Converts the current selection entirely into lowercase.
1501 **/
1502 toLowerCase(): void;
1503
1504 /**
1505 * Converts the current selection entirely into uppercase.
1506 **/
1507 toUpperCase(): void;
1508
1509 /**
1510 * Inserts an indentation into the current cursor position or indents the selected lines.
1511 **/
1512 indent(): void;
1513
1514 /**
1515 * Indents the current line.
1516 **/
1517 blockIndent(): void;
1518
1519 /**
1520 * Outdents the current line.
1521 **/
1522 blockOutdent(arg?: string): void;
1523
1524 /**
1525 * Given the currently selected range, this function either comments all the lines, or uncomments all of them.
1526 **/
1527 toggleCommentLines(): void;
1528
1529 /**
1530 * Works like [[EditSession.getTokenAt]], except it returns a number.
1531 **/
1532 getNumberAt(): number;
1533
1534 /**
1535 * If the character before the cursor is a number, this functions changes its value by `amount`.
1536 * @param amount The value to change the numeral by (can be negative to decrease value)
1537 **/
1538 modifyNumber(amount: number): void;
1539
1540 /**
1541 * Removes all the lines in the current selection
1542 **/
1543 removeLines(): void;
1544
1545 /**
1546 * Shifts all the selected lines down one row.
1547 **/
1548 moveLinesDown(): number;
1549
1550 /**
1551 * Shifts all the selected lines up one row.
1552 **/
1553 moveLinesUp(): number;
1554
1555 /**
1556 * Moves a range of text from the given range to the given position. `toPosition` is an object that looks like this:
1557 * ```json
1558 * { row: newRowLocation, column: newColumnLocation }
1559 * ```
1560 * @param fromRange The range of text you want moved within the document
1561 * @param toPosition The location (row and column) where you want to move the text to
1562 **/
1563 moveText(fromRange: Range, toPosition: any): Range;
1564
1565 /**
1566 * Copies all the selected lines up one row.
1567 **/
1568 copyLinesUp(): number;
1569
1570 /**
1571 * Copies all the selected lines down one row.
1572 **/
1573 copyLinesDown(): number;
1574
1575 /**
1576 * {:VirtualRenderer.getFirstVisibleRow}
1577 **/
1578 getFirstVisibleRow(): number;
1579
1580 /**
1581 * {:VirtualRenderer.getLastVisibleRow}
1582 **/
1583 getLastVisibleRow(): number;
1584
1585 /**
1586 * Indicates if the row is currently visible on the screen.
1587 * @param row The row to check
1588 **/
1589 isRowVisible(row: number): boolean;
1590
1591 /**
1592 * Indicates if the entire row is currently visible on the screen.
1593 * @param row The row to check
1594 **/
1595 isRowFullyVisible(row: number): boolean;
1596
1597 /**
1598 * Selects the text from the current position of the document until where a "page down" finishes.
1599 **/
1600 selectPageDown(): void;
1601
1602 /**
1603 * Selects the text from the current position of the document until where a "page up" finishes.
1604 **/
1605 selectPageUp(): void;
1606
1607 /**
1608 * Shifts the document to wherever "page down" is, as well as moving the cursor position.
1609 **/
1610 gotoPageDown(): void;
1611
1612 /**
1613 * Shifts the document to wherever "page up" is, as well as moving the cursor position.
1614 **/
1615 gotoPageUp(): void;
1616
1617 /**
1618 * Scrolls the document to wherever "page down" is, without changing the cursor position.
1619 **/
1620 scrollPageDown(): void;
1621
1622 /**
1623 * Scrolls the document to wherever "page up" is, without changing the cursor position.
1624 **/
1625 scrollPageUp(): void;
1626
1627 /**
1628 * Moves the editor to the specified row.
1629 **/
1630 scrollToRow(): void;
1631
1632 /**
1633 * Scrolls to a line. If `center` is `true`, it puts the line in middle of screen (or attempts to).
1634 * @param line The line to scroll to
1635 * @param center If `true`
1636 * @param animate If `true` animates scrolling
1637 * @param callback Function to be called when the animation has finished
1638 **/
1639 scrollToLine(line: number, center: boolean, animate: boolean, callback: Function): void;
1640
1641 /**
1642 * Attempts to center the current selection on the screen.
1643 **/
1644 centerSelection(): void;
1645
1646 /**
1647 * Gets the current position of the cursor.
1648 **/
1649 getCursorPosition(): Position;
1650
1651 /**
1652 * Returns the screen position of the cursor.
1653 **/
1654 getCursorPositionScreen(): number;
1655
1656 /**
1657 * {:Selection.getRange}
1658 **/
1659 getSelectionRange(): Range;
1660
1661 /**
1662 * Selects all the text in editor.
1663 **/
1664 selectAll(): void;
1665
1666 /**
1667 * {:Selection.clearSelection}
1668 **/
1669 clearSelection(): void;
1670
1671 /**
1672 * Moves the cursor to the specified row and column. Note that this does not de-select the current selection.
1673 * @param row The new row number
1674 * @param column The new column number
1675 **/
1676 moveCursorTo(row: number, column?: number, animate?:boolean): void;
1677
1678 /**
1679 * Moves the cursor to the position indicated by `pos.row` and `pos.column`.
1680 * @param position An object with two properties, row and column
1681 **/
1682 moveCursorToPosition(position: Position): void;
1683
1684 /**
1685 * Moves the cursor's row and column to the next matching bracket.
1686 **/
1687 jumpToMatching(): void;
1688
1689 /**
1690 * Moves the cursor to the specified line number, and also into the indiciated column.
1691 * @param lineNumber The line number to go to
1692 * @param column A column number to go to
1693 * @param animate If `true` animates scolling
1694 **/
1695 gotoLine(lineNumber: number, column?: number, animate?: boolean): void;
1696
1697 /**
1698 * Moves the cursor to the specified row and column. Note that this does de-select the current selection.
1699 * @param row The new row number
1700 * @param column The new column number
1701 **/
1702 navigateTo(row: number, column: number): void;
1703
1704 /**
1705 * Moves the cursor up in the document the specified number of times. Note that this does de-select the current selection.
1706 * @param times The number of times to change navigation
1707 **/
1708 navigateUp(times?: number): void;
1709
1710 /**
1711 * Moves the cursor down in the document the specified number of times. Note that this does de-select the current selection.
1712 * @param times The number of times to change navigation
1713 **/
1714 navigateDown(times?: number): void;
1715
1716 /**
1717 * Moves the cursor left in the document the specified number of times. Note that this does de-select the current selection.
1718 * @param times The number of times to change navigation
1719 **/
1720 navigateLeft(times?: number): void;
1721
1722 /**
1723 * Moves the cursor right in the document the specified number of times. Note that this does de-select the current selection.
1724 * @param times The number of times to change navigation
1725 **/
1726 navigateRight(times: number): void;
1727
1728 /**
1729 * Moves the cursor to the start of the current line. Note that this does de-select the current selection.
1730 **/
1731 navigateLineStart(): void;
1732
1733 /**
1734 * Moves the cursor to the end of the current line. Note that this does de-select the current selection.
1735 **/
1736 navigateLineEnd(): void;
1737
1738 /**
1739 * Moves the cursor to the end of the current file. Note that this does de-select the current selection.
1740 **/
1741 navigateFileEnd(): void;
1742
1743 /**
1744 * Moves the cursor to the start of the current file. Note that this does de-select the current selection.
1745 **/
1746 navigateFileStart(): void;
1747
1748 /**
1749 * Moves the cursor to the word immediately to the right of the current position. Note that this does de-select the current selection.
1750 **/
1751 navigateWordRight(): void;
1752
1753 /**
1754 * Moves the cursor to the word immediately to the left of the current position. Note that this does de-select the current selection.
1755 **/
1756 navigateWordLeft(): void;
1757
1758 /**
1759 * Replaces the first occurance of `options.needle` with the value in `replacement`.
1760 * @param replacement The text to replace with
1761 * @param options The [[Search `Search`]] options to use
1762 **/
1763 replace(replacement: string, options?: any): void;
1764
1765 /**
1766 * Replaces all occurances of `options.needle` with the value in `replacement`.
1767 * @param replacement The text to replace with
1768 * @param options The [[Search `Search`]] options to use
1769 **/
1770 replaceAll(replacement: string, options?: any): void;
1771
1772 /**
1773 * {:Search.getOptions} For more information on `options`, see [[Search `Search`]].
1774 **/
1775 getLastSearchOptions(): any;
1776
1777 /**
1778 * Attempts to find `needle` within the document. For more information on `options`, see [[Search `Search`]].
1779 * @param needle The text to search for (optional)
1780 * @param options An object defining various search properties
1781 * @param animate If `true` animate scrolling
1782 **/
1783 find(needle: string, options?: any, animate?: boolean): void;
1784
1785 /**
1786 * Performs another search for `needle` in the document. For more information on `options`, see [[Search `Search`]].
1787 * @param options search options
1788 * @param animate If `true` animate scrolling
1789 **/
1790 findNext(options?: any, animate?: boolean): void;
1791
1792 /**
1793 * Performs a search for `needle` backwards. For more information on `options`, see [[Search `Search`]].
1794 * @param options search options
1795 * @param animate If `true` animate scrolling
1796 **/
1797 findPrevious(options?: any, animate?: boolean): void;
1798
1799 /**
1800 * {:UndoManager.undo}
1801 **/
1802 undo(): void;
1803
1804 /**
1805 * {:UndoManager.redo}
1806 **/
1807 redo(): void;
1808
1809 /**
1810 * Cleans up the entire editor.
1811 **/
1812 destroy(): void;
1813
1814 }
1815
1816 var Editor: {
1817 /**
1818 * Creates a new `Editor` object.
1819 * @param renderer Associated `VirtualRenderer` that draws everything
1820 * @param session The `EditSession` to refer to
1821 **/
1822 new(renderer: VirtualRenderer, session?: IEditSession): Editor;
1823 }
1824
1825 interface EditorChangeEvent {
1826 start: Position;
1827 end: Position;
1828 action: string; // insert, remove
1829 lines: any[];
1830 }
1831
1832 ////////////////////////////////
1833 /// PlaceHolder
1834 ////////////////////////////////
1835
1836 export interface PlaceHolder {
1837
1838 on(event: string, fn: (e: any) => any): void;
1839
1840 /**
1841 * PlaceHolder.setup()
1842 * TODO
1843 **/
1844 setup(): void;
1845
1846 /**
1847 * PlaceHolder.showOtherMarkers()
1848 * TODO
1849 **/
1850 showOtherMarkers(): void;
1851
1852 /**
1853 * PlaceHolder.hideOtherMarkers()
1854 * Hides all over markers in the [[EditSession `EditSession`]] that are not the currently selected one.
1855 **/
1856 hideOtherMarkers(): void;
1857
1858 /**
1859 * PlaceHolder@onUpdate(e)
1860 * Emitted when the place holder updates.
1861 **/
1862 onUpdate(): void;
1863
1864 /**
1865 * PlaceHolder@onCursorChange(e)
1866 * Emitted when the cursor changes.
1867 **/
1868 onCursorChange(): void;
1869
1870 /**
1871 * PlaceHolder.detach()
1872 * TODO
1873 **/
1874 detach(): void;
1875
1876 /**
1877 * PlaceHolder.cancel()
1878 * TODO
1879 **/
1880 cancel(): void;
1881 }
1882 var PlaceHolder: {
1883 /**
1884 * - @param session (Document): The document to associate with the anchor
1885 * - @param length (Number): The starting row position
1886 * - @param pos (Number): The starting column position
1887 * - @param others (String):
1888 * - @param mainClass (String):
1889 * - @param othersClass (String):
1890 **/
1891 new (session: Document, length: number, pos: number, others: string, mainClass: string, othersClass: string): PlaceHolder;
1892
1893 new (session: IEditSession, length: number, pos: Position, positions: Position[]): PlaceHolder;
1894 }
1895
1896 ////////////////
1897 /// RangeList
1898 ////////////////
1899
1900 export interface IRangeList {
1901 ranges: Range[];
1902
1903 pointIndex(pos: Position, startIndex?: number): void;
1904
1905 addList(ranges: Range[]): void;
1906
1907 add(ranges: Range): void;
1908
1909 merge(): Range[];
1910
1911 substractPoint(pos: Position): void;
1912 }
1913 export var RangeList: {
1914 new (): IRangeList;
1915 }
1916
1917 ////////////////
1918 /// Range
1919 ////////////////
1920
1921 /**
1922 * This object is used in various places to indicate a region within the editor. To better visualize how this works, imagine a rectangle. Each quadrant of the rectangle is analogus to a range, as ranges contain a starting row and starting column, and an ending row, and ending column.
1923 **/
1924 export interface Range {
1925
1926 startRow:number;
1927
1928 startColumn:number;
1929
1930 endRow:number;
1931
1932 endColumn:number;
1933
1934 start: Position;
1935
1936 end: Position;
1937
1938 isEmpty(): boolean;
1939
1940 /**
1941 * Returns `true` if and only if the starting row and column, and ending row and column, are equivalent to those given by `range`.
1942 * @param range A range to check against
1943 **/
1944 isEqual(range: Range): void;
1945
1946 /**
1947 * Returns a string containing the range's row and column information, given like this:
1948 * ```
1949 * [start.row/start.column] -> [end.row/end.column]
1950 * ```
1951 **/
1952 toString(): void;
1953
1954 /**
1955 * Returns `true` if the `row` and `column` provided are within the given range. This can better be expressed as returning `true` if:
1956 * ```javascript
1957 * this.start.row <= row <= this.end.row &&
1958 * this.start.column <= column <= this.end.column
1959 * ```
1960 * @param row A row to check for
1961 * @param column A column to check for
1962 **/
1963 contains(row: number, column: number): boolean;
1964
1965 /**
1966 * Compares `this` range (A) with another range (B).
1967 * @param range A range to compare with
1968 **/
1969 compareRange(range: Range): number;
1970
1971 /**
1972 * Checks the row and column points of `p` with the row and column points of the calling range.
1973 * @param p A point to compare with
1974 **/
1975 comparePoint(p: Range): number;
1976
1977 /**
1978 * Checks the start and end points of `range` and compares them to the calling range. Returns `true` if the `range` is contained within the caller's range.
1979 * @param range A range to compare with
1980 **/
1981 containsRange(range: Range): boolean;
1982
1983 /**
1984 * Returns `true` if passed in `range` intersects with the one calling this method.
1985 * @param range A range to compare with
1986 **/
1987 intersects(range: Range): boolean;
1988
1989 /**
1990 * Returns `true` if the caller's ending row point is the same as `row`, and if the caller's ending column is the same as `column`.
1991 * @param row A row point to compare with
1992 * @param column A column point to compare with
1993 **/
1994 isEnd(row: number, column: number): boolean;
1995
1996 /**
1997 * Returns `true` if the caller's starting row point is the same as `row`, and if the caller's starting column is the same as `column`.
1998 * @param row A row point to compare with
1999 * @param column A column point to compare with
2000 **/
2001 isStart(row: number, column: number): boolean;
2002
2003 /**
2004 * Sets the starting row and column for the range.
2005 * @param row A row point to set
2006 * @param column A column point to set
2007 **/
2008 setStart(row: number, column: number): void;
2009
2010 /**
2011 * Sets the starting row and column for the range.
2012 * @param row A row point to set
2013 * @param column A column point to set
2014 **/
2015 setEnd(row: number, column: number): void;
2016
2017 /**
2018 * Returns `true` if the `row` and `column` are within the given range.
2019 * @param row A row point to compare with
2020 * @param column A column point to compare with
2021 **/
2022 inside(row: number, column: number): boolean;
2023
2024 /**
2025 * Returns `true` if the `row` and `column` are within the given range's starting points.
2026 * @param row A row point to compare with
2027 * @param column A column point to compare with
2028 **/
2029 insideStart(row: number, column: number): boolean;
2030
2031 /**
2032 * Returns `true` if the `row` and `column` are within the given range's ending points.
2033 * @param row A row point to compare with
2034 * @param column A column point to compare with
2035 **/
2036 insideEnd(row: number, column: number): boolean;
2037
2038 /**
2039 * Checks the row and column points with the row and column points of the calling range.
2040 * @param row A row point to compare with
2041 * @param column A column point to compare with
2042 **/
2043 compare(row: number, column: number): number;
2044
2045 /**
2046 * Checks the row and column points with the row and column points of the calling range.
2047 * @param row A row point to compare with
2048 * @param column A column point to compare with
2049 **/
2050 compareStart(row: number, column: number): number;
2051
2052 /**
2053 * Checks the row and column points with the row and column points of the calling range.
2054 * @param row A row point to compare with
2055 * @param column A column point to compare with
2056 **/
2057 compareEnd(row: number, column: number): number;
2058
2059 /**
2060 * Checks the row and column points with the row and column points of the calling range.
2061 * @param row A row point to compare with
2062 * @param column A column point to compare with
2063 **/
2064 compareInside(row: number, column: number): number;
2065
2066 /**
2067 * Returns the part of the current `Range` that occurs within the boundaries of `firstRow` and `lastRow` as a new `Range` object.
2068 * @param firstRow The starting row
2069 * @param lastRow The ending row
2070 **/
2071 clipRows(firstRow: number, lastRow: number): Range;
2072
2073 /**
2074 * Changes the row and column points for the calling range for both the starting and ending points.
2075 * @param row A new row to extend to
2076 * @param column A new column to extend to
2077 **/
2078 extend(row: number, column: number): Range;
2079
2080 /**
2081 * Returns `true` if the range spans across multiple lines.
2082 **/
2083 isMultiLine(): boolean;
2084
2085 /**
2086 * Returns a duplicate of the calling range.
2087 **/
2088 clone(): Range;
2089
2090 /**
2091 * Returns a range containing the starting and ending rows of the original range, but with a column value of `0`.
2092 **/
2093 collapseRows(): Range;
2094
2095 /**
2096 * Given the current `Range`, this function converts those starting and ending points into screen positions, and then returns a new `Range` object.
2097 * @param session The `EditSession` to retrieve coordinates from
2098 **/
2099 toScreenRange(session: IEditSession): Range;
2100
2101 /**
2102 * Creates and returns a new `Range` based on the row and column of the given parameters.
2103 * @param start A starting point to use
2104 * @param end An ending point to use
2105 **/
2106 fromPoints(start: Range, end: Range): Range;
2107
2108 }
2109 /**
2110 * Creates a new `Range` object with the given starting and ending row and column points.
2111 * @param startRow The starting row
2112 * @param startColumn The starting column
2113 * @param endRow The ending row
2114 * @param endColumn The ending column
2115 **/
2116 var Range: {
2117 fromPoints(pos1: Position, pos2: Position): Range;
2118 new(startRow: number, startColumn: number, endRow: number, endColumn: number): Range;
2119 }
2120
2121 ////////////////
2122 /// RenderLoop
2123 ////////////////
2124
2125 export interface RenderLoop { }
2126 var RenderLoop: {
2127 new(): RenderLoop;
2128 }
2129
2130 ////////////////
2131 /// ScrollBar
2132 ////////////////
2133
2134 /**
2135 * A set of methods for setting and retrieving the editor's scrollbar.
2136 **/
2137 export interface ScrollBar {
2138
2139 /**
2140 * Emitted when the scroll bar, well, scrolls.
2141 * @param e Contains one property, `"data"`, which indicates the current scroll top position
2142 **/
2143 onScroll(e: any): void;
2144
2145 /**
2146 * Returns the width of the scroll bar.
2147 **/
2148 getWidth(): number;
2149
2150 /**
2151 * Sets the height of the scroll bar, in pixels.
2152 * @param height The new height
2153 **/
2154 setHeight(height: number): void;
2155
2156 /**
2157 * Sets the inner height of the scroll bar, in pixels.
2158 * @param height The new inner height
2159 **/
2160 setInnerHeight(height: number): void;
2161
2162 /**
2163 * Sets the scroll top of the scroll bar.
2164 * @param scrollTop The new scroll top
2165 **/
2166 setScrollTop(scrollTop: number): void;
2167 }
2168 var ScrollBar: {
2169 /**
2170 * Creates a new `ScrollBar`. `parent` is the owner of the scroll bar.
2171 * @param parent A DOM element
2172 **/
2173 new(parent: HTMLElement): ScrollBar;
2174 }
2175
2176 ////////////////
2177 /// Search
2178 ////////////////
2179
2180 /**
2181 * A class designed to handle all sorts of text searches within a [[Document `Document`]].
2182 **/
2183 export interface Search {
2184
2185 /**
2186 * Sets the search options via the `options` parameter.
2187 * @param options An object containing all the new search properties
2188 **/
2189 set(options: any): Search;
2190
2191 /**
2192 * [Returns an object containing all the search options.]{: #Search.getOptions}
2193 **/
2194 getOptions(): any;
2195
2196 /**
2197 * Sets the search options via the `options` parameter.
2198 * @param An object containing all the search propertie
2199 **/
2200 setOptions(An: any): void;
2201
2202 /**
2203 * Searches for `options.needle`. If found, this method returns the [[Range `Range`]] where the text first occurs. If `options.backwards` is `true`, the search goes backwards in the session.
2204 * @param session The session to search with
2205 **/
2206 find(session: IEditSession): Range;
2207
2208 /**
2209 * Searches for all occurances `options.needle`. If found, this method returns an array of [[Range `Range`s]] where the text first occurs. If `options.backwards` is `true`, the search goes backwards in the session.
2210 * @param session The session to search with
2211 **/
2212 findAll(session: IEditSession): Range[];
2213
2214 /**
2215 * Searches for `options.needle` in `input`, and, if found, replaces it with `replacement`.
2216 * @param input The text to search in
2217 * @param replacement The replacing text
2218 * + (String): If `options.regExp` is `true`, this function returns `input` with the replacement already made. Otherwise, this function just returns `replacement`.<br/>
2219 * If `options.needle` was not found, this function returns `null`.
2220 **/
2221 replace(input: string, replacement: string): string;
2222 }
2223 var Search: {
2224 /**
2225 * Creates a new `Search` object. The following search options are avaliable:
2226 * - `needle`: The string or regular expression you're looking for
2227 * - `backwards`: Whether to search backwards from where cursor currently is. Defaults to `false`.
2228 * - `wrap`: Whether to wrap the search back to the beginning when it hits the end. Defaults to `false`.
2229 * - `caseSensitive`: Whether the search ought to be case-sensitive. Defaults to `false`.
2230 * - `wholeWord`: Whether the search matches only on whole words. Defaults to `false`.
2231 * - `range`: The [[Range]] to search within. Set this to `null` for the whole document
2232 * - `regExp`: Whether the search is a regular expression or not. Defaults to `false`.
2233 * - `start`: The starting [[Range]] or cursor position to begin the search
2234 * - `skipCurrent`: Whether or not to include the current line in the search. Default to `false`.
2235 **/
2236 new(): Search;
2237 }
2238
2239 ////////////////
2240 /// Search
2241 ////////////////
2242
2243 /**
2244 * Contains the cursor position and the text selection of an edit session.
2245 * The row/columns used in the selection are in document coordinates representing ths coordinates as thez appear in the document before applying soft wrap and folding.
2246 **/
2247 export interface Selection {
2248
2249 on(ev: string, callback: Function): void;
2250
2251 addEventListener(ev: string, callback: Function): void;
2252
2253 off(ev: string, callback: Function): void;
2254
2255 removeListener(ev: string, callback: Function): void;
2256
2257 removeEventListener(ev: string, callback: Function): void;
2258
2259 moveCursorWordLeft(): void;
2260
2261 moveCursorWordRight(): void;
2262
2263 fromOrientedRange(range: Range): void;
2264
2265 setSelectionRange(match: any): void;
2266
2267 getAllRanges(): Range[];
2268
2269 on(event: string, fn: (e: any) => any): void;
2270
2271 addRange(range: Range): void;
2272
2273 /**
2274 * Returns `true` if the selection is empty.
2275 **/
2276 isEmpty(): boolean;
2277
2278 /**
2279 * Returns `true` if the selection is a multi-line.
2280 **/
2281 isMultiLine(): boolean;
2282
2283 /**
2284 * Gets the current position of the cursor.
2285 **/
2286 getCursor(): Position;
2287
2288 /**
2289 * Sets the row and column position of the anchor. This function also emits the `'changeSelection'` event.
2290 * @param row The new row
2291 * @param column The new column
2292 **/
2293 setSelectionAnchor(row: number, column: number): void;
2294
2295 /**
2296 * Returns an object containing the `row` and `column` of the calling selection anchor.
2297 **/
2298 getSelectionAnchor(): any;
2299
2300 /**
2301 * Returns an object containing the `row` and `column` of the calling selection lead.
2302 **/
2303 getSelectionLead(): any;
2304
2305 /**
2306 * Shifts the selection up (or down, if [[Selection.isBackwards `isBackwards()`]] is true) the given number of columns.
2307 * @param columns The number of columns to shift by
2308 **/
2309 shiftSelection(columns: number): void;
2310
2311 /**
2312 * Returns `true` if the selection is going backwards in the document.
2313 **/
2314 isBackwards(): boolean;
2315
2316 /**
2317 * [Returns the [[Range]] for the selected text.]{: #Selection.getRange}
2318 **/
2319 getRange(): Range;
2320
2321 /**
2322 * [Empties the selection (by de-selecting it). This function also emits the `'changeSelection'` event.]{: #Selection.clearSelection}
2323 **/
2324 clearSelection(): void;
2325
2326 /**
2327 * Selects all the text in the document.
2328 **/
2329 selectAll(): void;
2330
2331 /**
2332 * Sets the selection to the provided range.
2333 * @param range The range of text to select
2334 * @param reverse Indicates if the range should go backwards (`true`) or not
2335 **/
2336 setRange(range: Range, reverse: boolean): void;
2337
2338 /**
2339 * Moves the selection cursor to the indicated row and column.
2340 * @param row The row to select to
2341 * @param column The column to select to
2342 **/
2343 selectTo(row: number, column: number): void;
2344
2345 /**
2346 * Moves the selection cursor to the row and column indicated by `pos`.
2347 * @param pos An object containing the row and column
2348 **/
2349 selectToPosition(pos: any): void;
2350
2351 /**
2352 * Moves the selection up one row.
2353 **/
2354 selectUp(): void;
2355
2356 /**
2357 * Moves the selection down one row.
2358 **/
2359 selectDown(): void;
2360
2361 /**
2362 * Moves the selection right one column.
2363 **/
2364 selectRight(): void;
2365
2366 /**
2367 * Moves the selection left one column.
2368 **/
2369 selectLeft(): void;
2370
2371 /**
2372 * Moves the selection to the beginning of the current line.
2373 **/
2374 selectLineStart(): void;
2375
2376 /**
2377 * Moves the selection to the end of the current line.
2378 **/
2379 selectLineEnd(): void;
2380
2381 /**
2382 * Moves the selection to the end of the file.
2383 **/
2384 selectFileEnd(): void;
2385
2386 /**
2387 * Moves the selection to the start of the file.
2388 **/
2389 selectFileStart(): void;
2390
2391 /**
2392 * Moves the selection to the first word on the right.
2393 **/
2394 selectWordRight(): void;
2395
2396 /**
2397 * Moves the selection to the first word on the left.
2398 **/
2399 selectWordLeft(): void;
2400
2401 /**
2402 * Moves the selection to highlight the entire word.
2403 **/
2404 getWordRange(): void;
2405
2406 /**
2407 * Selects an entire word boundary.
2408 **/
2409 selectWord(): void;
2410
2411 /**
2412 * Selects a word, including its right whitespace.
2413 **/
2414 selectAWord(): void;
2415
2416 /**
2417 * Selects the entire line.
2418 **/
2419 selectLine(): void;
2420
2421 /**
2422 * Moves the cursor up one row.
2423 **/
2424 moveCursorUp(): void;
2425
2426 /**
2427 * Moves the cursor down one row.
2428 **/
2429 moveCursorDown(): void;
2430
2431 /**
2432 * Moves the cursor left one column.
2433 **/
2434 moveCursorLeft(): void;
2435
2436 /**
2437 * Moves the cursor right one column.
2438 **/
2439 moveCursorRight(): void;
2440
2441 /**
2442 * Moves the cursor to the start of the line.
2443 **/
2444 moveCursorLineStart(): void;
2445
2446 /**
2447 * Moves the cursor to the end of the line.
2448 **/
2449 moveCursorLineEnd(): void;
2450
2451 /**
2452 * Moves the cursor to the end of the file.
2453 **/
2454 moveCursorFileEnd(): void;
2455
2456 /**
2457 * Moves the cursor to the start of the file.
2458 **/
2459 moveCursorFileStart(): void;
2460
2461 /**
2462 * Moves the cursor to the word on the right.
2463 **/
2464 moveCursorLongWordRight(): void;
2465
2466 /**
2467 * Moves the cursor to the word on the left.
2468 **/
2469 moveCursorLongWordLeft(): void;
2470
2471 /**
2472 * Moves the cursor to position indicated by the parameters. Negative numbers move the cursor backwards in the document.
2473 * @param rows The number of rows to move by
2474 * @param chars The number of characters to move by
2475 **/
2476 moveCursorBy(rows: number, chars: number): void;
2477
2478 /**
2479 * Moves the selection to the position indicated by its `row` and `column`.
2480 * @param position The position to move to
2481 **/
2482 moveCursorToPosition(position: any): void;
2483
2484 /**
2485 * Moves the cursor to the row and column provided. [If `preventUpdateDesiredColumn` is `true`, then the cursor stays in the same column position as its original point.]{: #preventUpdateBoolDesc}
2486 * @param row The row to move to
2487 * @param column The column to move to
2488 * @param keepDesiredColumn [If `true`, the cursor move does not respect the previous column]{: #preventUpdateBool}
2489 **/
2490 moveCursorTo(row: number, column: number, keepDesiredColumn?: boolean): void;
2491
2492 /**
2493 * Moves the cursor to the screen position indicated by row and column. {:preventUpdateBoolDesc}
2494 * @param row The row to move to
2495 * @param column The column to move to
2496 * @param keepDesiredColumn {:preventUpdateBool}
2497 **/
2498 moveCursorToScreen(row: number, column: number, keepDesiredColumn: boolean): void;
2499 }
2500 var Selection: {
2501 /**
2502 * Creates a new `Selection` object.
2503 * @param session The session to use
2504 **/
2505 new(session: IEditSession): Selection;
2506 }
2507
2508 ////////////////
2509 /// Split
2510 ////////////////
2511
2512 export interface Split {
2513
2514 BELOW: number;
2515 BESIDE: number;
2516
2517 /**
2518 * Returns the number of splits.
2519 **/
2520 getSplits(): number;
2521
2522 /**
2523 * Set the number of splits.
2524 * @param splits The number of splits
2525 **/
2526 setSplits(splits?: number): void;
2527
2528 /**
2529 * Returns the editor identified by the index `idx`.
2530 * @param idx The index of the editor you want
2531 **/
2532 getEditor(idx: number): Editor;
2533
2534 /**
2535 * Returns the current editor.
2536 **/
2537 getCurrentEditor(): Editor;
2538
2539 /**
2540 * Focuses the current editor.
2541 **/
2542 focus(): void;
2543
2544 /**
2545 * Blurs the current editor.
2546 **/
2547 blur(): void;
2548
2549 /**
2550 * Sets a theme for each of the available editors.
2551 * @param theme The name of the theme to set
2552 **/
2553 setTheme(theme: string): void;
2554
2555 /**
2556 * Sets the keyboard handler for the editor.
2557 * @param keybinding
2558 **/
2559 setKeyboardHandler(keybinding: string): void;
2560
2561 /**
2562 * Executes `callback` on all of the available editors.
2563 * @param callback A callback function to execute
2564 * @param scope The default scope for the callback
2565 **/
2566 forEach(callback: Function, scope: string): void;
2567
2568 /**
2569 * Sets the font size, in pixels, for all the available editors.
2570 * @param size The new font size
2571 **/
2572 setFontSize(size: number): void;
2573
2574 /**
2575 * Sets a new [[EditSession `EditSession`]] for the indicated editor.
2576 * @param session The new edit session
2577 * @param idx The editor's index you're interested in
2578 **/
2579 setSession(session: IEditSession, idx: number): void;
2580
2581 /**
2582 * Returns the orientation.
2583 **/
2584 getOrientation(): number;
2585
2586 /**
2587 * Sets the orientation.
2588 * @param orientation The new orientation value
2589 **/
2590 setOrientation(orientation: number): void;
2591
2592 /**
2593 * Resizes the editor.
2594 **/
2595 resize(): void;
2596 }
2597 var Split: {
2598 Split(container: HTMLElement, theme?: any, splits?: number): void;
2599 }
2600
2601 //////////////////
2602 /// TokenIterator
2603 //////////////////
2604
2605 /**
2606 * This class provides an essay way to treat the document as a stream of tokens, and provides methods to iterate over these tokens.
2607 **/
2608 export interface TokenIterator {
2609
2610 /**
2611 * Tokenizes all the items from the current point to the row prior in the document.
2612 **/
2613 stepBackward(): string[];
2614
2615 /**
2616 * Tokenizes all the items from the current point until the next row in the document. If the current point is at the end of the file, this function returns `null`. Otherwise, it returns the tokenized string.
2617 **/
2618 stepForward(): string;
2619
2620 /**
2621 * Returns the current tokenized string.
2622 **/
2623 getCurrentToken(): TokenInfo;
2624
2625 /**
2626 * Returns the current row.
2627 **/
2628 getCurrentTokenRow(): number;
2629
2630 /**
2631 * Returns the current column.
2632 **/
2633 getCurrentTokenColumn(): number;
2634 }
2635 var TokenIterator: {
2636 /**
2637 * Creates a new token iterator object. The inital token index is set to the provided row and column coordinates.
2638 * @param session The session to associate with
2639 * @param initialRow The row to start the tokenizing at
2640 * @param initialColumn The column to start the tokenizing at
2641 **/
2642 new(session: IEditSession, initialRow: number, initialColumn: number): TokenIterator;
2643 }
2644
2645 //////////////////
2646 /// Tokenizer
2647 //////////////////
2648
2649
2650 /**
2651 * This class takes a set of highlighting rules, and creates a tokenizer out of them. For more information, see [the wiki on extending highlighters](https://github.com/ajaxorg/ace/wiki/Creating-or-Extending-an-Edit-Mode#wiki-extendingTheHighlighter).
2652 **/
2653 export interface Tokenizer {
2654
2655 /**
2656 * Returns an object containing two properties: `tokens`, which contains all the tokens; and `state`, the current state.
2657 **/
2658 removeCapturingGroups(src: string): string;
2659 createSplitterRegexp(src: string, flag?: string): RegExp;
2660 getLineTokens(line: string, startState: string | string[]): TokenInfo[];
2661 }
2662 var Tokenizer: {
2663 /**
2664 * Constructs a new tokenizer based on the given rules and flags.
2665 * @param rules The highlighting rules
2666 * @param flag Any additional regular expression flags to pass (like "i" for case insensitive)
2667 **/
2668 new(rules: any, flag: string): Tokenizer;
2669 }
2670
2671 //////////////////
2672 /// UndoManager
2673 //////////////////
2674
2675 /**
2676 * This object maintains the undo stack for an [[EditSession `EditSession`]].
2677 **/
2678 export interface UndoManager {
2679
2680 /**
2681 * [Perform an undo operation on the document, reverting the last change.]{: #UndoManager.undo}
2682 * @param session {:session}
2683 * @param dontSelect {:dontSelect}
2684 **/
2685 undo(session?: IEditSession, dontSelect?: boolean): Range;
2686
2687 /**
2688 * [Perform a redo operation on the document, reimplementing the last change.]{: #UndoManager.redo}
2689 * @param session {:session}
2690 * @param dontSelect {:dontSelect}
2691 **/
2692 redo(session?: IEditSession, dontSelect?: boolean): void;
2693
2694 /**
2695 * Destroys the stack of undo and redo redo operations.
2696 **/
2697 reset(): void;
2698
2699 /**
2700 * Returns `true` if there are undo operations left to perform.
2701 **/
2702 canUndo(): boolean;
2703 /**
2704 * Alias for canUndo
2705 **/
2706 hasUndo(): boolean;
2707
2708 /**
2709 * Returns `true` if there are redo operations left to perform.
2710 **/
2711 canRedo(): boolean;
2712 /**
2713 * Alias for canRedo
2714 **/
2715 hasRedo(): boolean;
2716
2717 /**
2718 * Returns if the current status is clean
2719 **/
2720 isAtBookmark(): boolean;
2721 /**
2722 * Alias for isAtBookmark
2723 **/
2724 isClean(): boolean;
2725
2726 /**
2727 * Marks the current status clean
2728 * @param rev {:rev}
2729 **/
2730 bookmark(rev?: number): void;
2731 /**
2732 * Alias for bookmark
2733 **/
2734 markClean(rev?: number): void;
2735
2736 }
2737 var UndoManager: {
2738 /**
2739 * Resets the current undo state and creates a new `UndoManager`.
2740 **/
2741 new(): UndoManager;
2742 }
2743
2744 ////////////////////
2745 /// VirtualRenderer
2746 ////////////////////
2747
2748 /**
2749 * The class that is responsible for drawing everything you see on the screen!
2750 **/
2751 export interface VirtualRenderer extends OptionProvider {
2752
2753 scroller: any;
2754
2755 characterWidth: number;
2756
2757 lineHeight: number;
2758
2759 $cursorLayer: Layer.Cursor;
2760
2761 setScrollMargin(top:number, bottom:number, left: number, right: number): void;
2762
2763 screenToTextCoordinates(left: number, top: number): void;
2764
2765 /**
2766 * Associates the renderer with an [[EditSession `EditSession`]].
2767 **/
2768 setSession(session: IEditSession): void;
2769
2770 /**
2771 * Triggers a partial update of the text, from the range given by the two parameters.
2772 * @param firstRow The first row to update
2773 * @param lastRow The last row to update
2774 **/
2775 updateLines(firstRow: number, lastRow: number): void;
2776
2777 /**
2778 * Triggers a full update of the text, for all the rows.
2779 **/
2780 updateText(): void;
2781
2782 /**
2783 * Triggers a full update of all the layers, for all the rows.
2784 * @param force If `true`, forces the changes through
2785 **/
2786 updateFull(force: boolean): void;
2787
2788 /**
2789 * Updates the font size.
2790 **/
2791 updateFontSize(): void;
2792
2793 /**
2794 * [Triggers a resize of the editor.]{: #VirtualRenderer.onResize}
2795 * @param force If `true`, recomputes the size, even if the height and width haven't changed
2796 * @param gutterWidth The width of the gutter in pixels
2797 * @param width The width of the editor in pixels
2798 * @param height The hiehgt of the editor, in pixels
2799 **/
2800 onResize(force: boolean, gutterWidth: number, width: number, height: number): void;
2801
2802 /**
2803 * Adjusts the wrap limit, which is the number of characters that can fit within the width of the edit area on screen.
2804 **/
2805 adjustWrapLimit(): void;
2806
2807 /**
2808 * Identifies whether you want to have an animated scroll or not.
2809 * @param shouldAnimate Set to `true` to show animated scrolls
2810 **/
2811 setAnimatedScroll(shouldAnimate: boolean): void;
2812
2813 /**
2814 * Returns whether an animated scroll happens or not.
2815 **/
2816 getAnimatedScroll(): boolean;
2817
2818 /**
2819 * Identifies whether you want to show invisible characters or not.
2820 * @param showInvisibles Set to `true` to show invisibles
2821 **/
2822 setShowInvisibles(showInvisibles: boolean): void;
2823
2824 /**
2825 * Returns whether invisible characters are being shown or not.
2826 **/
2827 getShowInvisibles(): boolean;
2828
2829 /**
2830 * Identifies whether you want to show the print margin or not.
2831 * @param showPrintMargin Set to `true` to show the print margin
2832 **/
2833 setShowPrintMargin(showPrintMargin: boolean): void;
2834
2835 /**
2836 * Returns whether the print margin is being shown or not.
2837 **/
2838 getShowPrintMargin(): boolean;
2839
2840 /**
2841 * Identifies whether you want to show the print margin column or not.
2842 * @param showPrintMargin Set to `true` to show the print margin column
2843 **/
2844 setPrintMarginColumn(showPrintMargin: boolean): void;
2845
2846 /**
2847 * Returns whether the print margin column is being shown or not.
2848 **/
2849 getPrintMarginColumn(): boolean;
2850
2851 /**
2852 * Returns `true` if the gutter is being shown.
2853 **/
2854 getShowGutter(): boolean;
2855
2856 /**
2857 * Identifies whether you want to show the gutter or not.
2858 * @param show Set to `true` to show the gutter
2859 **/
2860 setShowGutter(show: boolean): void;
2861
2862 /**
2863 * Returns the root element containing this renderer.
2864 **/
2865 getContainerElement(): HTMLElement;
2866
2867 /**
2868 * Returns the element that the mouse events are attached to
2869 **/
2870 getMouseEventTarget(): HTMLElement;
2871
2872 /**
2873 * Returns the element to which the hidden text area is added.
2874 **/
2875 getTextAreaContainer(): HTMLElement;
2876
2877 /**
2878 * [Returns the index of the first visible row.]{: #VirtualRenderer.getFirstVisibleRow}
2879 **/
2880 getFirstVisibleRow(): number;
2881
2882 /**
2883 * Returns the index of the first fully visible row. "Fully" here means that the characters in the row are not truncated; that the top and the bottom of the row are on the screen.
2884 **/
2885 getFirstFullyVisibleRow(): number;
2886
2887 /**
2888 * Returns the index of the last fully visible row. "Fully" here means that the characters in the row are not truncated; that the top and the bottom of the row are on the screen.
2889 **/
2890 getLastFullyVisibleRow(): number;
2891
2892 /**
2893 * [Returns the index of the last visible row.]{: #VirtualRenderer.getLastVisibleRow}
2894 **/
2895 getLastVisibleRow(): number;
2896
2897 /**
2898 * Sets the padding for all the layers.
2899 * @param padding A new padding value (in pixels)
2900 **/
2901 setPadding(padding: number): void;
2902
2903 /**
2904 * Returns whether the horizontal scrollbar is set to be always visible.
2905 **/
2906 getHScrollBarAlwaysVisible(): boolean;
2907
2908 /**
2909 * Identifies whether you want to show the horizontal scrollbar or not.
2910 * @param alwaysVisible Set to `true` to make the horizontal scroll bar visible
2911 **/
2912 setHScrollBarAlwaysVisible(alwaysVisible: boolean): void;
2913
2914 /**
2915 * Schedules an update to all the front markers in the document.
2916 **/
2917 updateFrontMarkers(): void;
2918
2919 /**
2920 * Schedules an update to all the back markers in the document.
2921 **/
2922 updateBackMarkers(): void;
2923
2924 /**
2925 * Deprecated; (moved to [[EditSession]])
2926 **/
2927 addGutterDecoration(): void;
2928
2929 /**
2930 * Deprecated; (moved to [[EditSession]])
2931 **/
2932 removeGutterDecoration(): void;
2933
2934 /**
2935 * Redraw breakpoints.
2936 **/
2937 updateBreakpoints(): void;
2938
2939 /**
2940 * Sets annotations for the gutter.
2941 * @param annotations An array containing annotations
2942 **/
2943 setAnnotations(annotations: any[]): void;
2944
2945 /**
2946 * Updates the cursor icon.
2947 **/
2948 updateCursor(): void;
2949
2950 /**
2951 * Hides the cursor icon.
2952 **/
2953 hideCursor(): void;
2954
2955 /**
2956 * Shows the cursor icon.
2957 **/
2958 showCursor(): void;
2959
2960 /**
2961 * Scrolls the cursor into the first visibile area of the editor
2962 **/
2963 scrollCursorIntoView(): void;
2964
2965 /**
2966 * {:EditSession.getScrollTop}
2967 **/
2968 getScrollTop(): number;
2969
2970 /**
2971 * {:EditSession.getScrollLeft}
2972 **/
2973 getScrollLeft(): number;
2974
2975 /**
2976 * Returns the first visible row, regardless of whether it's fully visible or not.
2977 **/
2978 getScrollTopRow(): number;
2979
2980 /**
2981 * Returns the last visible row, regardless of whether it's fully visible or not.
2982 **/
2983 getScrollBottomRow(): number;
2984
2985 /**
2986 * Gracefully scrolls from the top of the editor to the row indicated.
2987 * @param row A row id
2988 **/
2989 scrollToRow(row: number): void;
2990
2991 /**
2992 * Gracefully scrolls the editor to the row indicated.
2993 * @param line A line number
2994 * @param center If `true`, centers the editor the to indicated line
2995 * @param animate If `true` animates scrolling
2996 * @param callback Function to be called after the animation has finished
2997 **/
2998 scrollToLine(line: number, center: boolean, animate: boolean, callback: Function): void;
2999
3000 /**
3001 * Scrolls the editor to the y pixel indicated.
3002 * @param scrollTop The position to scroll to
3003 **/
3004 scrollToY(scrollTop: number): number;
3005
3006 /**
3007 * Scrolls the editor across the x-axis to the pixel indicated.
3008 * @param scrollLeft The position to scroll to
3009 **/
3010 scrollToX(scrollLeft: number): number;
3011
3012 /**
3013 * Scrolls the editor across both x- and y-axes.
3014 * @param deltaX The x value to scroll by
3015 * @param deltaY The y value to scroll by
3016 **/
3017 scrollBy(deltaX: number, deltaY: number): void;
3018
3019 /**
3020 * Returns `true` if you can still scroll by either parameter; in other words, you haven't reached the end of the file or line.
3021 * @param deltaX The x value to scroll by
3022 * @param deltaY The y value to scroll by
3023 **/
3024 isScrollableBy(deltaX: number, deltaY: number): boolean;
3025
3026 /**
3027 * Returns an object containing the `pageX` and `pageY` coordinates of the document position.
3028 * @param row The document row position
3029 * @param column The document column position
3030 **/
3031 textToScreenCoordinates(row: number, column: number): any;
3032
3033 /**
3034 * Focuses the current container.
3035 **/
3036 visualizeFocus(): void;
3037
3038 /**
3039 * Blurs the current container.
3040 **/
3041 visualizeBlur(): void;
3042
3043 /**
3044 * undefined
3045 * @param position
3046 **/
3047 showComposition(position: number): void;
3048
3049 /**
3050 * Sets the inner text of the current composition to `text`.
3051 * @param text A string of text to use
3052 **/
3053 setCompositionText(text: string): void;
3054
3055 /**
3056 * Hides the current composition.
3057 **/
3058 hideComposition(): void;
3059
3060 /**
3061 * [Sets a new theme for the editor. `theme` should exist, and be a directory path, like `ace/theme/textmate`.]{: #VirtualRenderer.setTheme}
3062 * @param theme The path to a theme
3063 **/
3064 setTheme(theme: string): void;
3065
3066 /**
3067 * [Returns the path of the current theme.]{: #VirtualRenderer.getTheme}
3068 **/
3069 getTheme(): string;
3070
3071 /**
3072 * [Adds a new class, `style`, to the editor.]{: #VirtualRenderer.setStyle}
3073 * @param style A class name
3074 **/
3075 setStyle(style: string): void;
3076
3077 /**
3078 * [Removes the class `style` from the editor.]{: #VirtualRenderer.unsetStyle}
3079 * @param style A class name
3080 **/
3081 unsetStyle(style: string): void;
3082
3083 /**
3084 * Destroys the text and cursor layers for this renderer.
3085 **/
3086 destroy(): void;
3087
3088 }
3089 var VirtualRenderer: {
3090 /**
3091 * Constructs a new `VirtualRenderer` within the `container` specified, applying the given `theme`.
3092 * @param container The root element of the editor
3093 * @param theme The starting theme
3094 **/
3095 new(container: HTMLElement, theme?: string): VirtualRenderer;
3096 }
3097
3098 export interface Completer {
3099 /**
3100 * Provides possible completion results asynchronously using the given callback.
3101 * @param editor The editor to associate with
3102 * @param session The `EditSession` to refer to
3103 * @param pos An object containing the row and column
3104 * @param prefix The prefixing string before the current position
3105 * @param callback Function to provide the results or error
3106 */
3107 getCompletions: (editor: Editor, session: IEditSession, pos: Position, prefix: string, callback: CompletionCallback) => void;
3108
3109 /**
3110 * Provides tooltip information about a completion result.
3111 * @param item The completion result
3112 */
3113 getDocTooltip?: ((item: Completion) => void) | undefined;
3114 }
3115
3116 export interface Completion {
3117 value: string;
3118 meta: string;
3119 type?: string | undefined;
3120 caption?: string | undefined;
3121 snippet?: any;
3122 score?: number | undefined;
3123 exactMatch?: number | undefined;
3124 docHTML?: string | undefined;
3125 }
3126
3127 export type CompletionCallback = (error: Error | null, results: Completion[]) => void;
3128
3129 ////////////////////
3130 /// Layer
3131 ////////////////////
3132
3133 export namespace Layer {
3134
3135 ////////////////////
3136 /// Cursor
3137 ////////////////////
3138
3139 export interface Cursor {
3140 setBlinking(blinking: boolean): void;
3141 setBlinkInterval(blinkInterval: number): void;
3142 hideCursor(): void;
3143 showCursor(): void;
3144 }
3145 }
3146}
3147
3148declare var ace: AceAjax.Ace;
3149
\No newline at end of file