|
| 1 | +// Type definitions for CodeMirror |
| 2 | +// Project: https://github.com/marijnh/CodeMirror |
| 3 | +// Definitions by: jacqt <https://github.com/jacqt> |
| 4 | +// Definitions: https://github.com/borisyankov/DefinitelyTyped |
| 5 | + |
| 6 | +declare module CodeMirror { |
| 7 | + var commands : any; |
| 8 | + |
| 9 | + /** Provides a framework for showing autocompletion hints. Defines editor.showHint, which takes an optional |
| 10 | + options object, and pops up a widget that allows the user to select a completion. Finding hints is done with |
| 11 | + a hinting functions (the hint option), which is a function that take an editor instance and options object, |
| 12 | + and return a {list, from, to} object, where list is an array of strings or objects (the completions), and |
| 13 | + from and to give the start and end of the token that is being completed as {line, ch} objects. An optional |
| 14 | + selectedHint property (an integer) can be added to the completion object to control the initially selected hint. */ |
| 15 | + function showHint (cm: CodeMirror.Doc, hinter?: (doc : CodeMirror.Doc) => Hints, options?: IShowHintOptions) : void; |
| 16 | + |
| 17 | + |
| 18 | + interface Hints { |
| 19 | + from: Position; |
| 20 | + to: Position; |
| 21 | + list: Hint[] | string[]; |
| 22 | + } |
| 23 | + |
| 24 | + /** Interface used by showHint.js Codemirror add-on |
| 25 | + When completions aren't simple strings, they should be objects with the following properties: */ |
| 26 | + interface Hint { |
| 27 | + text: string; |
| 28 | + className?: string; |
| 29 | + displayText?: string; |
| 30 | + from?: Position; |
| 31 | + render?: (element: any, self: any, data: any) => void; |
| 32 | + to?: Position; |
| 33 | + } |
| 34 | + |
| 35 | + interface Editor { |
| 36 | + /** An extension of the existing CodeMirror typings for the Editor.on("keyup", func) syntax */ |
| 37 | + on(eventName: string, handler: (doc: CodeMirror.Doc, event : any ) => void ): void; |
| 38 | + off(eventName: string, handler: (doc: CodeMirror.Doc, event : any) => void ): void; |
| 39 | + } |
| 40 | + |
| 41 | + /** Extend CodeMirror.Doc with a state object, so that the Doc.state.completionActive property is reachable*/ |
| 42 | + interface Doc { |
| 43 | + state: any; |
| 44 | + showHint: (options: IShowHintOptions) => void; |
| 45 | + } |
| 46 | + |
| 47 | + interface IShowHintOptions { |
| 48 | + completeSingle: boolean; |
| 49 | + hint: (doc : CodeMirror.Doc) => Hints; |
| 50 | + } |
| 51 | + |
| 52 | + /** The Handle used to interact with the autocomplete dialog box.*/ |
| 53 | + interface Handle { |
| 54 | + moveFocus(n: number, avoidWrap: boolean): void; |
| 55 | + setFocus(n: number): void; |
| 56 | + menuSize(): number; |
| 57 | + length: number; |
| 58 | + close(): void; |
| 59 | + pick(): void; |
| 60 | + data: any; |
| 61 | + } |
| 62 | +} |
0 commit comments