From a8746f5fd19d82b1c11722d13ea09452de49ddcd Mon Sep 17 00:00:00 2001 From: ukrukarg Date: Thu, 9 Feb 2017 15:04:52 -0800 Subject: [PATCH] Added some missing declaration to codemirror (#14268) --- codemirror/codemirror-showhint.d.ts | 13 +++++++++++-- codemirror/index.d.ts | 10 +++++++--- codemirror/test/index.ts | 6 ++++++ codemirror/test/showhint.ts | 14 ++++++++++++++ 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/codemirror/codemirror-showhint.d.ts b/codemirror/codemirror-showhint.d.ts index 72c34b6007..55a3d6012b 100644 --- a/codemirror/codemirror-showhint.d.ts +++ b/codemirror/codemirror-showhint.d.ts @@ -16,7 +16,7 @@ declare module "codemirror" { and return a {list, from, to} object, where list is an array of strings or objects (the completions), and from and to give the start and end of the token that is being completed as {line, ch} objects. An optional selectedHint property (an integer) can be added to the completion object to control the initially selected hint. */ - function showHint(cm: CodeMirror.Doc, hinter?: (doc: CodeMirror.Doc) => Hints, options?: ShowHintOptions): void; + function showHint(cm: CodeMirror.Doc, hinter?: HintFunction, options?: ShowHintOptions): void; interface Hints { from: Position; @@ -47,9 +47,18 @@ declare module "codemirror" { showHint: (options: ShowHintOptions) => void; } + interface HintFunction { + (doc: CodeMirror.Doc): Hints; + } + + interface AsyncHintFunction { + (doc: CodeMirror.Doc, callback: (hints: Hints) => any): any; + async?: boolean; + } + interface ShowHintOptions { completeSingle: boolean; - hint: (doc: CodeMirror.Doc) => Hints; + hint: HintFunction | AsyncHintFunction; } /** The Handle used to interact with the autocomplete dialog box.*/ diff --git a/codemirror/index.d.ts b/codemirror/index.d.ts index 4af27f5f12..d0b2dd6511 100644 --- a/codemirror/index.d.ts +++ b/codemirror/index.d.ts @@ -118,6 +118,8 @@ declare namespace CodeMirror { The other arguments and the returned value have the same interpretation as they have in findPosH. */ findPosV(start: CodeMirror.Position, amount: number, unit: string): { line: number; ch: number; hitSide?: boolean; }; + /** Returns the start and end of the 'word' (the stretch of letters, whitespace, or punctuation) at the given position. */ + findWordAt(pos: CodeMirror.Position): CodeMirror.Range; /** Change the configuration of the editor. option should the name of an option, and value should be a valid value for that option. */ setOption(option: string, value: any): void; @@ -672,9 +674,11 @@ declare namespace CodeMirror { (line: number, ch?: number): Position; } - interface Range{ - from: CodeMirror.Position; - to: CodeMirror.Position; + interface Range { + anchor: CodeMirror.Position; + head: CodeMirror.Position; + from(): CodeMirror.Position; + to(): CodeMirror.Position; } interface Position { diff --git a/codemirror/test/index.ts b/codemirror/test/index.ts index b46604b1bb..41b7170fd1 100644 --- a/codemirror/test/index.ts +++ b/codemirror/test/index.ts @@ -7,6 +7,12 @@ var myCodeMirror2: CodeMirror.Editor = CodeMirror(document.body, { mode: "javascript" }); +var range = myCodeMirror2.findWordAt(CodeMirror.Pos(0, 2)); +var anchor = range.anchor; +var head = range.head; +var from = range.from(); +var to = range.to(); + var myTextArea: HTMLTextAreaElement; var myCodeMirror3: CodeMirror.Editor = CodeMirror(function (elt) { myTextArea.parentNode.replaceChild(elt, myTextArea); diff --git a/codemirror/test/showhint.ts b/codemirror/test/showhint.ts index 59521ed440..00dbe6bed4 100644 --- a/codemirror/test/showhint.ts +++ b/codemirror/test/showhint.ts @@ -31,3 +31,17 @@ CodeMirror.showHint(doc, function (cm) { to: pos }; }); +var asyncHintFunc : CodeMirror.AsyncHintFunction = + (doc: CodeMirror.Doc, callback: (hints: CodeMirror.Hints) => any) => { + callback({ + from: pos, + list: ["one", "two"], + to: pos + }); + }; +asyncHintFunc.async = true; + +doc.showHint({ + completeSingle: false, + hint: asyncHintFunc +})