123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140 |
- declare function CodeMirror(host: HTMLElement, options?: CodeMirror.EditorConfiguration): CodeMirror.Editor;
- declare function CodeMirror(callback: (host: HTMLElement) => void , options?: CodeMirror.EditorConfiguration): CodeMirror.Editor;
- declare module CodeMirror {
- export var Doc : CodeMirror.DocConstructor;
- export var Pos: CodeMirror.PositionConstructor;
- export var Pass: any;
- function fromTextArea(host: HTMLTextAreaElement, options?: EditorConfiguration): CodeMirror.EditorFromTextArea;
-
- interface modespec {
- name: string;
- mode: string;
- mime: string;
- }
- function findModeByName(name: string): modespec;
- function findModeByFileName(name: string): modespec;
- function findModeByMIME(mime: string): modespec;
- var modes: {
- [key: string]: any;
- };
- var mimeModes: {
- [key: string]: any;
- }
- interface modeinfo {
- ext: string[];
- mime: string;
- mode: string;
- name: string;
- }
- var modeInfo: modeinfo[];
- var version: string;
-
- function defineExtension(name: string, value: any): void;
-
- function defineDocExtension(name: string, value: any): void;
-
- function defineOption(name: string, default_: any, updateFunc: Function): void;
-
- function defineInitHook(func: Function): void;
- function on(element: any, eventName: string, handler: Function): void;
- function off(element: any, eventName: string, handler: Function): void;
-
- function on(doc: Doc, eventName: 'change', handler: (instance: Doc, change: EditorChange) => void ): void;
- function off(doc: Doc, eventName: 'change', handler: (instance: Doc, change: EditorChange) => void ): void;
-
- function on(doc: Doc, eventName: 'beforeChange', handler: (instance: Doc, change: EditorChangeCancellable) => void ): void;
- function off(doc: Doc, eventName: 'beforeChange', handler: (instance: Doc, change: EditorChangeCancellable) => void ): void;
-
- function on(doc: Doc, eventName: 'cursorActivity', handler: (instance: CodeMirror.Editor) => void ): void;
- function off(doc: Doc, eventName: 'cursorActivity', handler: (instance: CodeMirror.Editor) => void ): void;
-
- function on(doc: Doc, eventName: 'beforeSelectionChange', handler: (instance: CodeMirror.Editor, selection: { head: Position; anchor: Position; }) => void ): void;
- function off(doc: Doc, eventName: 'beforeSelectionChange', handler: (instance: CodeMirror.Editor, selection: { head: Position; anchor: Position; }) => void ): void;
-
- function on(line: LineHandle, eventName: 'delete', handler: () => void ): void;
- function off(line: LineHandle, eventName: 'delete', handler: () => void ): void;
-
- function on(line: LineHandle, eventName: 'change', handler: (line: LineHandle, change: EditorChange) => void ): void;
- function off(line: LineHandle, eventName: 'change', handler: (line: LineHandle, change: EditorChange) => void ): void;
-
- function on(marker: TextMarker, eventName: 'beforeCursorEnter', handler: () => void ): void;
- function off(marker: TextMarker, eventName: 'beforeCursorEnter', handler: () => void ): void;
-
- function on(marker: TextMarker, eventName: 'clear', handler: () => void ): void;
- function off(marker: TextMarker, eventName: 'clear', handler: () => void ): void;
-
- function on(marker: TextMarker, eventName: 'hide', handler: () => void ): void;
- function off(marker: TextMarker, eventName: 'hide', handler: () => void ): void;
-
- function on(marker: TextMarker, eventName: 'unhide', handler: () => void ): void;
- function off(marker: TextMarker, eventName: 'unhide', handler: () => void ): void;
-
- function on(line: LineWidget, eventName: 'redraw', handler: () => void ): void;
- function off(line: LineWidget, eventName: 'redraw', handler: () => void ): void;
-
- function signal(target: any, name: string, ...args: any[]): void;
- interface Editor {
-
- hasFocus(): boolean;
-
- findPosH(start: CodeMirror.Position, amount: number, unit: string, visually: boolean): { line: number; ch: number; hitSide?: boolean; };
-
- findPosV(start: CodeMirror.Position, amount: number, unit: string): { line: number; ch: number; hitSide?: boolean; };
-
- setOption(option: string, value: any): void;
-
- getOption(option: string): any;
-
- addKeyMap(map: any, bottom?: boolean): void;
-
- removeKeyMap(map: any): void;
-
- addOverlay(mode: any, options?: any): void;
-
- removeOverlay(mode: any): void;
-
- getDoc(): CodeMirror.Doc;
-
- swapDoc(doc: CodeMirror.Doc): CodeMirror.Doc;
-
- setGutterMarker(line: any, gutterID: string, value: HTMLElement): CodeMirror.LineHandle;
-
- clearGutter(gutterID: string): void;
-
- addLineClass(line: any, where: string, _class_: string): CodeMirror.LineHandle;
-
- removeLineClass(line: any, where: string, class_: string): CodeMirror.LineHandle;
-
- lineInfo(line: any): {
- line: any;
- handle: any;
- text: string;
-
- gutterMarks: any;
- textClass: string;
- bgClass: string;
- wrapClass: string;
-
- widgets: any;
- };
-
- addWidget(pos: CodeMirror.Position, node: HTMLElement, scrollIntoView: boolean): void;
-
- addLineWidget(line: any, node: HTMLElement, options?: {
-
- coverGutter: boolean;
-
- noHScroll: boolean;
-
- above: boolean;
-
- showIfHidden: boolean;
- }): CodeMirror.LineWidget;
-
- setSize(width: any, height: any): void;
-
- scrollTo(x: number, y: number): void;
-
- getScrollInfo(): {
- left: any;
- top: any;
- width: any;
- height: any;
- clientWidth: any;
- clientHeight: any;
- }
-
- scrollIntoView(pos: CodeMirror.Position, margin?: number): void;
-
- scrollIntoView(pos: { left: number; top: number; right: number; bottom: number; }, margin: number): void;
-
- scrollIntoView(pos: { line: number, ch: number }, margin?: number): void;
-
- scrollIntoView(pos: { from: CodeMirror.Position, to: CodeMirror.Position }, margin: number): void;
-
- cursorCoords(where: boolean, mode: string): { left: number; top: number; bottom: number; };
-
- cursorCoords(where: CodeMirror.Position, mode: string): { left: number; top: number; bottom: number; };
-
- charCoords(pos: CodeMirror.Position, mode: string): { left: number; right: number; top: number; bottom: number; };
-
- coordsChar(object: { left: number; top: number; }, mode?: string): CodeMirror.Position;
-
- defaultTextHeight(): number;
-
- defaultCharWidth(): number;
-
- getViewport(): { from: number; to: number };
-
- refresh(): void;
-
- getTokenAt(pos: CodeMirror.Position): {
-
- start: number;
-
- end: number;
-
- string: string;
-
- type: string;
-
- state: any;
- };
-
- getStateAfter(line?: number): any;
-
- operation<T>(fn: ()=> T): T;
- /** Adjust the indentation of the given line.
- The second argument (which defaults to "smart") may be one of:
- "prev" Base indentation on the indentation of the previous line.
- "smart" Use the mode's smart indentation if available, behave like "prev" otherwise.
- "add" Increase the indentation of the line by one indent unit.
- "subtract" Reduce the indentation of the line. */
- indentLine(line: number, dir?: string): void;
- /** Give the editor focus. */
- focus(): void;
- /** Returns the hidden textarea used to read input. */
- getInputField(): HTMLTextAreaElement;
- /** Returns the DOM node that represents the editor, and controls its size. Remove this from your tree to delete an editor instance. */
- getWrapperElement(): HTMLElement;
- /** Returns the DOM node that is responsible for the scrolling of the editor. */
- getScrollerElement(): HTMLElement;
- /** Fetches the DOM node that contains the editor gutters. */
- getGutterElement(): HTMLElement;
- /** Events are registered with the on method (and removed with the off method).
- These are the events that fire on the instance object. The name of the event is followed by the arguments that will be passed to the handler.
- The instance argument always refers to the editor instance. */
- on(eventName: string, handler: (instance: CodeMirror.Editor) => void ): void;
- off(eventName: string, handler: (instance: CodeMirror.Editor) => void ): void;
- /** Fires every time the content of the editor is changed. */
- on(eventName: 'change', handler: (instance: CodeMirror.Editor, change: CodeMirror.EditorChange) => void ): void;
- off(eventName: 'change', handler: (instance: CodeMirror.Editor, change: CodeMirror.EditorChange) => void ): void;
- /** Like the "change" event, but batched per operation, passing an
- * array containing all the changes that happened in the operation.
- * This event is fired after the operation finished, and display
- * changes it makes will trigger a new operation. */
- on(eventName: 'changes', handler: (instance: CodeMirror.Editor, change: CodeMirror.EditorChange[]) => void ): void;
- off(eventName: 'changes', handler: (instance: CodeMirror.Editor, change: CodeMirror.EditorChange[]) => void ): void;
- /** This event is fired before a change is applied, and its handler may choose to modify or cancel the change.
- The changeObj never has a next property, since this is fired for each individual change, and not batched per operation.
- Note: you may not do anything from a "beforeChange" handler that would cause changes to the document or its visualization.
- Doing so will, since this handler is called directly from the bowels of the CodeMirror implementation,
- probably cause the editor to become corrupted. */
- on(eventName: 'beforeChange', handler: (instance: CodeMirror.Editor, change: CodeMirror.EditorChangeCancellable) => void ): void;
- off(eventName: 'beforeChange', handler: (instance: CodeMirror.Editor, change: CodeMirror.EditorChangeCancellable) => void ): void;
- /** Will be fired when the cursor or selection moves, or any change is made to the editor content. */
- on(eventName: 'cursorActivity', handler: (instance: CodeMirror.Editor) => void ): void;
- off(eventName: 'cursorActivity', handler: (instance: CodeMirror.Editor) => void ): void;
- /** This event is fired before the selection is moved. Its handler may modify the resulting selection head and anchor.
- Handlers for this event have the same restriction as "beforeChange" handlers � they should not do anything to directly update the state of the editor. */
- on(eventName: 'beforeSelectionChange', handler: (instance: CodeMirror.Editor, selection: { head: CodeMirror.Position; anchor: CodeMirror.Position; }) => void ): void;
- off(eventName: 'beforeSelectionChange', handler: (instance: CodeMirror.Editor, selection: { head: CodeMirror.Position; anchor: CodeMirror.Position; }) => void ): void;
- /** Fires whenever the view port of the editor changes (due to scrolling, editing, or any other factor).
- The from and to arguments give the new start and end of the viewport. */
- on(eventName: 'viewportChange', handler: (instance: CodeMirror.Editor, from: number, to: number) => void ): void;
- off(eventName: 'viewportChange', handler: (instance: CodeMirror.Editor, from: number, to: number) => void ): void;
- /** Fires when the editor gutter (the line-number area) is clicked. Will pass the editor instance as first argument,
- the (zero-based) number of the line that was clicked as second argument, the CSS class of the gutter that was clicked as third argument,
- and the raw mousedown event object as fourth argument. */
- on(eventName: 'gutterClick', handler: (instance: CodeMirror.Editor, line: number, gutter: string, clickEvent: Event) => void ): void;
- off(eventName: 'gutterClick', handler: (instance: CodeMirror.Editor, line: number, gutter: string, clickEvent: Event) => void ): void;
- /** Fires whenever the editor is focused. */
- on(eventName: 'focus', handler: (instance: CodeMirror.Editor) => void ): void;
- off(eventName: 'focus', handler: (instance: CodeMirror.Editor) => void ): void;
- /** Fires whenever the editor is unfocused. */
- on(eventName: 'blur', handler: (instance: CodeMirror.Editor) => void ): void;
- off(eventName: 'blur', handler: (instance: CodeMirror.Editor) => void ): void;
- /** Fires when the editor is scrolled. */
- on(eventName: 'scroll', handler: (instance: CodeMirror.Editor) => void ): void;
- off(eventName: 'scroll', handler: (instance: CodeMirror.Editor) => void ): void;
- /** Will be fired whenever CodeMirror updates its DOM display. */
- on(eventName: 'update', handler: (instance: CodeMirror.Editor) => void ): void;
- off(eventName: 'update', handler: (instance: CodeMirror.Editor) => void ): void;
- /** Fired whenever a line is (re-)rendered to the DOM. Fired right after the DOM element is built, before it is added to the document.
- The handler may mess with the style of the resulting element, or add event handlers, but should not try to change the state of the editor. */
- on(eventName: 'renderLine', handler: (instance: CodeMirror.Editor, line: number, element: HTMLElement) => void ): void;
- off(eventName: 'renderLine', handler: (instance: CodeMirror.Editor, line: number, element: HTMLElement) => void ): void;
- }
- interface EditorFromTextArea extends Editor {
- /** Copy the content of the editor into the textarea. */
- save(): void;
- /** Remove the editor, and restore the original textarea (with the editor's current content). */
- toTextArea(): void;
- /** Returns the textarea that the instance was based on. */
- getTextArea(): HTMLTextAreaElement;
- }
- interface DocConstructor {
- new (text: string, mode?: any, firstLineNumber?: number, lineSep?: string): Doc;
- (text: string, mode?: any, firstLineNumber?: number, lineSep?: string): Doc;
- }
- interface Doc {
- /** Get the current editor content. You can pass it an optional argument to specify the string to be used to separate lines (defaults to "\n"). */
- getValue(seperator?: string): string;
- /** Set the editor content. */
- setValue(content: string): void;
- /** Get the text between the given points in the editor, which should be {line, ch} objects.
- An optional third argument can be given to indicate the line separator string to use (defaults to "\n"). */
- getRange(from: Position, to: CodeMirror.Position, seperator?: string): string;
- /** Replace the part of the document between from and to with the given string.
- from and to must be {line, ch} objects. to can be left off to simply insert the string at position from. */
- replaceRange(replacement: string, from: CodeMirror.Position, to: CodeMirror.Position): void;
- /** Get the content of line n. */
- getLine(n: number): string;
- /** Set the content of line n. */
- setLine(n: number, text: string): void;
- /** Remove the given line from the document. */
- removeLine(n: number): void;
- /** Get the number of lines in the editor. */
- lineCount(): number;
- /** Get the first line of the editor. This will usually be zero but for linked sub-views,
- or documents instantiated with a non-zero first line, it might return other values. */
- firstLine(): number;
- /** Get the last line of the editor. This will usually be lineCount() - 1, but for linked sub-views, it might return other values. */
- lastLine(): number;
- /** Fetches the line handle for the given line number. */
- getLineHandle(num: number): CodeMirror.LineHandle;
- /** Given a line handle, returns the current position of that line (or null when it is no longer in the document). */
- getLineNumber(handle: CodeMirror.LineHandle): number;
- /** Iterate over the whole document, and call f for each line, passing the line handle.
- This is a faster way to visit a range of line handlers than calling getLineHandle for each of them.
- Note that line handles have a text property containing the line's content (as a string). */
- eachLine(f: (line: CodeMirror.LineHandle) => void ): void;
- /** Iterate over the range from start up to (not including) end, and call f for each line, passing the line handle.
- This is a faster way to visit a range of line handlers than calling getLineHandle for each of them.
- Note that line handles have a text property containing the line's content (as a string). */
- eachLine(start: number, end: number, f: (line: CodeMirror.LineHandle) => void ): void;
- /** Set the editor content as 'clean', a flag that it will retain until it is edited, and which will be set again when such an edit is undone again.
- Useful to track whether the content needs to be saved. */
- markClean(): void;
- /** Returns whether the document is currently clean (not modified since initialization or the last call to markClean). */
- isClean(): boolean;
- /** Get the currently selected code. */
- getSelection(): string;
- /** Replace the selection with the given string. By default, the new selection will span the inserted text.
- The optional collapse argument can be used to change this � passing "start" or "end" will collapse the selection to the start or end of the inserted text. */
- replaceSelection(replacement: string, collapse?: string): void;
- /** start is a an optional string indicating which end of the selection to return.
- It may be "start" , "end" , "head"(the side of the selection that moves when you press shift + arrow),
- or "anchor"(the fixed side of the selection).Omitting the argument is the same as passing "head".A { line , ch } object will be returned. */
- getCursor(start?: string): CodeMirror.Position;
- /** Retrieves a list of all current selections. These will always be sorted, and never overlap (overlapping selections are merged).
- Each object in the array contains anchor and head properties referring to {line, ch} objects. */
- listSelections(): { anchor: CodeMirror.Position; head: CodeMirror.Position }[];
- /** Return true if any text is selected. */
- somethingSelected(): boolean;
- /** Set the cursor position.You can either pass a single { line , ch } object , or the line and the character as two separate parameters. */
- setCursor(pos: CodeMirror.Position): void;
- /** Set the selection range.anchor and head should be { line , ch } objects.head defaults to anchor when not given. */
- setSelection(anchor: CodeMirror.Position, head: CodeMirror.Position): void;
- /** Similar to setSelection , but will, if shift is held or the extending flag is set,
- move the head of the selection while leaving the anchor at its current place.
- pos2 is optional , and can be passed to ensure a region (for example a word or paragraph) will end up selected
- (in addition to whatever lies between that region and the current anchor). */
- extendSelection(from: CodeMirror.Position, to?: CodeMirror.Position): void;
- /** Sets or clears the 'extending' flag , which acts similar to the shift key,
- in that it will cause cursor movement and calls to extendSelection to leave the selection anchor in place. */
- setExtending(value: boolean): void;
- /** Retrieve the editor associated with a document. May return null. */
- getEditor(): CodeMirror.Editor;
- /** Create an identical copy of the given doc. When copyHistory is true , the history will also be copied.Can not be called directly on an editor. */
- copy(copyHistory: boolean): CodeMirror.Doc;
- /** Create a new document that's linked to the target document. Linked documents will stay in sync (changes to one are also applied to the other) until unlinked. */
- linkedDoc(options: {
-
- sharedHist?: boolean;
- from?: number;
-
- to?: number;
-
- mode: any;
- }): CodeMirror.Doc;
- /** Break the link between two documents. After calling this , changes will no longer propagate between the documents,
- and, if they had a shared history, the history will become separate. */
- unlinkDoc(doc: CodeMirror.Doc): void;
- /** Will call the given function for all documents linked to the target document. It will be passed two arguments,
- the linked document and a boolean indicating whether that document shares history with the target. */
- iterLinkedDocs(fn: (doc: CodeMirror.Doc, sharedHist: boolean) => void ): void;
- /** Undo one edit (if any undo events are stored). */
- undo(): void;
- /** Redo one undone edit. */
- redo(): void;
- /** Returns an object with {undo, redo } properties , both of which hold integers , indicating the amount of stored undo and redo operations. */
- historySize(): { undo: number; redo: number; };
- /** Clears the editor's undo history. */
- clearHistory(): void;
- /** Get a(JSON - serializeable) representation of the undo history. */
- getHistory(): any;
- /** Replace the editor's undo history with the one provided, which must be a value as returned by getHistory.
- Note that this will have entirely undefined results if the editor content isn't also the same as it was when getHistory was called. */
- setHistory(history: any): void;
- /** Can be used to mark a range of text with a specific CSS class name. from and to should be { line , ch } objects. */
- markText(from: CodeMirror.Position, to: CodeMirror.Position, options?: CodeMirror.TextMarkerOptions): TextMarker;
- /** Inserts a bookmark, a handle that follows the text around it as it is being edited, at the given position.
- A bookmark has two methods find() and clear(). The first returns the current position of the bookmark, if it is still in the document,
- and the second explicitly removes the bookmark. */
- setBookmark(pos: CodeMirror.Position, options?: {
-
- widget?: HTMLElement;
-
- insertLeft?: boolean;
- }): CodeMirror.TextMarker;
- /** Returns an array of all the bookmarks and marked ranges found between the given positions. */
- findMarks(from: CodeMirror.Position, to: CodeMirror.Position): TextMarker[];
- /** Returns an array of all the bookmarks and marked ranges present at the given position. */
- findMarksAt(pos: CodeMirror.Position): TextMarker[];
- /** Returns an array containing all marked ranges in the document. */
- getAllMarks(): CodeMirror.TextMarker[];
- /** Gets the mode object for the editor. Note that this is distinct from getOption("mode"), which gives you the mode specification,
- rather than the resolved, instantiated mode object. */
- getMode(): any;
- /** Calculates and returns a { line , ch } object for a zero-based index whose value is relative to the start of the editor's text.
- If the index is out of range of the text then the returned object is clipped to start or end of the text respectively. */
- posFromIndex(index: number): CodeMirror.Position;
- /** The reverse of posFromIndex. */
- indexFromPos(object: CodeMirror.Position): number;
- }
- interface LineHandle {
- text: string;
- }
- interface TextMarker {
- /** Remove the mark. */
- clear(): void;
- /** Returns a {from, to} object (both holding document positions), indicating the current position of the marked range,
- or undefined if the marker is no longer in the document. */
- find(): CodeMirror.Position;
- /** Returns an object representing the options for the marker. If copyWidget is given true, it will clone the value of the replacedWith option, if any. */
- getOptions(copyWidget: boolean): CodeMirror.TextMarkerOptions;
- }
- interface LineWidget {
- /** Removes the widget. */
- clear(): void;
- /** Call this if you made some change to the widget's DOM node that might affect its height.
- It'll force CodeMirror to update the height of the line that contains the widget. */
- changed(): void;
- }
- interface EditorChange {
- /** Position (in the pre-change coordinate system) where the change started. */
- from: CodeMirror.Position;
- /** Position (in the pre-change coordinate system) where the change ended. */
- to: CodeMirror.Position;
- /** Array of strings representing the text that replaced the changed range (split by line). */
- text: string[];
- /** Text that used to be between from and to, which is overwritten by this change. */
- removed: string[];
- /** String representing the origin of the change event and wether it can be merged with history */
- origin: string;
- }
- interface EditorChangeCancellable extends CodeMirror.EditorChange {
- /** may be used to modify the change. All three arguments to update are optional, and can be left off to leave the existing value for that field intact. */
- update(from?: CodeMirror.Position, to?: CodeMirror.Position, text?: string): void;
- cancel(): void;
- }
- interface PositionConstructor {
- new (line: number, ch: number): Position;
- (line: number, ch: number): Position;
- }
- interface Position {
- ch: number;
- line: number;
- }
- interface EditorConfiguration {
- /** string| The starting value of the editor. Can be a string, or a document object. */
- value?: any;
- /** string|object. The mode to use. When not given, this will default to the first mode that was loaded.
- It may be a string, which either simply names the mode or is a MIME type associated with the mode.
- Alternatively, it may be an object containing configuration options for the mode,
- with a name property that names the mode (for example {name: "javascript", json: true}). */
- mode?: any;
- /** The theme to style the editor with. You must make sure the CSS file defining the corresponding .cm-s-[name] styles is loaded.
- The default is "default". */
- theme?: string;
- /** How many spaces a block (whatever that means in the edited language) should be indented. The default is 2. */
- indentUnit?: number;
- /** Whether to use the context-sensitive indentation that the mode provides (or just indent the same as the line before). Defaults to true. */
- smartIndent?: boolean;
- /** The width of a tab character. Defaults to 4. */
- tabSize?: number;
- /** Whether, when indenting, the first N*tabSize spaces should be replaced by N tabs. Default is false. */
- indentWithTabs?: boolean;
- /** Configures whether the editor should re-indent the current line when a character is typed
- that might change its proper indentation (only works if the mode supports indentation). Default is true. */
- electricChars?: boolean;
- /** Determines whether horizontal cursor movement through right-to-left (Arabic, Hebrew) text
- is visual (pressing the left arrow moves the cursor left)
- or logical (pressing the left arrow moves to the next lower index in the string, which is visually right in right-to-left text).
- The default is false on Windows, and true on other platforms. */
- rtlMoveVisually?: boolean;
- /** Configures the keymap to use. The default is "default", which is the only keymap defined in codemirror.js itself.
- Extra keymaps are found in the keymap directory. See the section on keymaps for more information. */
- keyMap?: string;
- /** Can be used to specify extra keybindings for the editor, alongside the ones defined by keyMap. Should be either null, or a valid keymap value. */
- extraKeys?: any;
- /** Whether CodeMirror should scroll or wrap for long lines. Defaults to false (scroll). */
- lineWrapping?: boolean;
- /** Whether to show line numbers to the left of the editor. */
- lineNumbers?: boolean;
- /** At which number to start counting lines. Default is 1. */
- firstLineNumber?: number;
- /** A function used to format line numbers. The function is passed the line number, and should return a string that will be shown in the gutter. */
- lineNumberFormatter?: (line: number) => string;
-
- gutters?: string[];
-
- fixedGutter?: boolean;
-
- readOnly?: any;
-
- showCursorWhenSelecting?: boolean;
-
- undoDepth?: number;
-
- historyEventDelay?: number;
-
- tabindex?: number;
-
- autofocus?: boolean;
-
- dragDrop?: boolean;
-
- onDragEvent?: (instance: CodeMirror.Editor, event: Event) => boolean;
-
- onKeyEvent?: (instance: CodeMirror.Editor, event: Event) => boolean;
-
- cursorBlinkRate?: number;
-
- cursorHeight?: number;
-
- workTime?: number;
-
- workDelay?: number;
-
- pollInterval?: number
-
- flattenSpans?: boolean;
-
- maxHighlightLength?: number;
-
- viewportMargin?: number;
-
- lint?: boolean | LintOptions;
-
- placeholder?: string;
- }
- interface TextMarkerOptions {
-
- className?: string;
-
- inclusiveLeft?: boolean;
-
- inclusiveRight?: boolean;
-
- atomic?: boolean;
-
- collapsed?: boolean;
-
- clearOnEnter?: boolean;
-
- clearWhenEmpty?: boolean;
-
- replacedWith?: HTMLElement;
-
- handleMouseEvents?: boolean;
-
- readOnly?: boolean;
-
- addToHistory?: boolean;
-
- startStyle?: string;
-
- endStyle?: string;
-
- css?: string;
-
- title?: string;
-
- shared?: boolean;
- }
- interface StringStream {
- lastColumnPos: number;
- lastColumnValue: number;
- lineStart: number;
-
- pos: number;
-
- start: number;
-
- string: string;
-
- tabSize: number;
-
- eol(): boolean;
-
- sol(): boolean;
-
- peek(): string;
-
- next(): string;
-
- eat(match: string): string;
- eat(match: RegExp): string;
- eat(match: (char: string) => boolean): string;
-
- eatWhile(match: string): boolean;
- eatWhile(match: RegExp): boolean;
- eatWhile(match: (char: string) => boolean): boolean;
-
- eatSpace(): boolean;
-
- skipToEnd(): void;
-
- skipTo(ch: string): boolean;
-
- match(pattern: string, consume?: boolean, caseFold?: boolean): boolean;
- match(pattern: RegExp, consume?: boolean): string[];
-
- backUp(n: number): void;
-
- column(): number;
-
- indentation(): number;
-
- current(): string;
- }
-
- interface Mode<T> {
-
- token(stream: StringStream, state: T): string;
-
- startState?: () => T;
-
- blankLine?: (state: T) => void;
-
- copyState?: (state: T) => T;
-
- indent?: (state: T, textAfter: string) => number;
-
-
- lineComment?: string;
-
- blockCommentStart?: string;
-
- blockCommentEnd?: string;
-
- blockCommentLead?: string;
-
- electricChars?: string
-
- electricinput?: RegExp
- }
-
- interface ModeFactory<T> {
- (config: CodeMirror.EditorConfiguration, modeOptions?: any): Mode<T>
- }
-
- function defineMode(id: string, modefactory: ModeFactory<any>): void;
- function defineMode(id: string, modefactory: ModeFactory<any>, base: any): void;
-
- function defineMIME(mimetype: string, mode: any): void;
-
- function multiplexingMode<T>(...modes: any[]): Mode<T>;
-
- function getMode<T>(config: CodeMirror.EditorConfiguration, mode: any): Mode<T>;
-
- function overlayMode<T, S>(base: Mode<T>, overlay: Mode<S>, combine?: boolean): Mode<any>
- /**
- * async specifies that the lint process runs asynchronously. hasGutters specifies that lint errors should be displayed in the CodeMirror
- * gutter, note that you must use this in conjunction with [ "CodeMirror-lint-markers" ] as an element in the gutters argument on
- * initialization of the CodeMirror instance.
- */
- interface LintStateOptions {
- async: boolean;
- hasGutters: boolean;
- }
-
- interface LintOptions extends LintStateOptions {
- getAnnotations: AnnotationsCallback;
- }
-
- interface AnnotationsCallback {
- (content: string, updateLintingCallback: UpdateLintingCallback, options: LintStateOptions, codeMirror: Editor): void;
- }
-
- interface UpdateLintingCallback {
- (codeMirror: Editor, annotations: Annotation[]): void;
- }
-
- interface Annotation {
- from: Position;
- message?: string;
- severity?: string;
- to?: Position;
- }
- }
- declare module "codemirror" {
- export = CodeMirror;
- }
|