You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3001 lines
96 KiB

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