Added some missing declaration to codemirror (#14268)

This commit is contained in:
ukrukarg
2017-02-09 15:04:52 -08:00
committed by Alex Eagle
parent fb8ab6a780
commit a8746f5fd1
4 changed files with 38 additions and 5 deletions
+11 -2
View File
@@ -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.*/
+7 -3
View File
@@ -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 {
+6
View File
@@ -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);
+14
View File
@@ -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
})