暫無描述
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.

ace.d.ts 92KB

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