From 20dae297ab3cb68b170f29584a152d7a633f71b0 Mon Sep 17 00:00:00 2001 From: mbilsing Date: Thu, 29 Jun 2017 11:17:30 +0200 Subject: [PATCH 1/2] Changes typings of CodeMirror's show-hint module to use the Editor object in most parameters instead of the Doc object. . --- types/codemirror/codemirror-showhint.d.ts | 13 +++++-------- types/codemirror/test/showhint.ts | 12 ++++++------ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/types/codemirror/codemirror-showhint.d.ts b/types/codemirror/codemirror-showhint.d.ts index 55a3d6012b..745e481737 100644 --- a/types/codemirror/codemirror-showhint.d.ts +++ b/types/codemirror/codemirror-showhint.d.ts @@ -1,6 +1,6 @@ // Type definitions for CodeMirror // Project: https://github.com/marijnh/CodeMirror -// Definitions by: jacqt , basarat +// Definitions by: jacqt , basarat , mbilsing // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // See docs https://codemirror.net/doc/manual.html#addon_show-hint @@ -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?: HintFunction, options?: ShowHintOptions): void; + function showHint(cm: CodeMirror.Editor, hinter?: HintFunction, options?: ShowHintOptions): void; interface Hints { from: Position; @@ -32,7 +32,7 @@ declare module "codemirror" { displayText?: string; from?: Position; /** Called if a completion is picked. If provided *you* are responsible for applying the completion */ - hint?: (cm: any, data: Hints, cur: Hint) => void; + hint?: (cm: CodeMirror.Editor, data: Hints, cur: Hint) => void; render?: (element: HTMLLIElement, data: Hints, cur: Hint) => void; to?: Position; } @@ -41,18 +41,15 @@ declare module "codemirror" { /** An extension of the existing CodeMirror typings for the Editor.on("keyup", func) syntax */ on(eventName: string, handler: (doc: CodeMirror.Doc, event: any) => void): void; off(eventName: string, handler: (doc: CodeMirror.Doc, event: any) => void): void; - } - - interface Doc { showHint: (options: ShowHintOptions) => void; } interface HintFunction { - (doc: CodeMirror.Doc): Hints; + (cm: CodeMirror.Editor): Hints; } interface AsyncHintFunction { - (doc: CodeMirror.Doc, callback: (hints: Hints) => any): any; + (cm: CodeMirror.Editor, callback: (hints: Hints) => any): any; async?: boolean; } diff --git a/types/codemirror/test/showhint.ts b/types/codemirror/test/showhint.ts index 00dbe6bed4..0aabcc9a86 100644 --- a/types/codemirror/test/showhint.ts +++ b/types/codemirror/test/showhint.ts @@ -1,16 +1,16 @@ -var doc = new CodeMirror.Doc('text'); +var cm = CodeMirror(document.body, {value: 'text'}); var pos = new CodeMirror.Pos(2, 3); -CodeMirror.showHint(doc); -CodeMirror.showHint(doc, function (cm) { +CodeMirror.showHint(cm); +CodeMirror.showHint(cm, function (cm) { return { from: pos, list: ["one", "two"], to: pos }; }); -CodeMirror.showHint(doc, function (cm) { +CodeMirror.showHint(cm, function (cm) { return { from: pos, list: [ @@ -32,7 +32,7 @@ CodeMirror.showHint(doc, function (cm) { }; }); var asyncHintFunc : CodeMirror.AsyncHintFunction = - (doc: CodeMirror.Doc, callback: (hints: CodeMirror.Hints) => any) => { + (cm: CodeMirror.Editor, callback: (hints: CodeMirror.Hints) => any) => { callback({ from: pos, list: ["one", "two"], @@ -41,7 +41,7 @@ var asyncHintFunc : CodeMirror.AsyncHintFunction = }; asyncHintFunc.async = true; -doc.showHint({ +cm.showHint({ completeSingle: false, hint: asyncHintFunc }) From 6cfc342e879fb3a3d3e2bd48dfd524997c96f1fd Mon Sep 17 00:00:00 2001 From: mbilsing Date: Thu, 29 Jun 2017 14:32:40 +0200 Subject: [PATCH 2/2] . --- types/codemirror/codemirror-showhint.d.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/types/codemirror/codemirror-showhint.d.ts b/types/codemirror/codemirror-showhint.d.ts index 745e481737..c6f367d0d2 100644 --- a/types/codemirror/codemirror-showhint.d.ts +++ b/types/codemirror/codemirror-showhint.d.ts @@ -1,6 +1,8 @@ // Type definitions for CodeMirror // Project: https://github.com/marijnh/CodeMirror -// Definitions by: jacqt , basarat , mbilsing +// Definitions by: jacqt +// basarat +// mbilsing // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // See docs https://codemirror.net/doc/manual.html#addon_show-hint