Skip to content

Commit 14465a5

Browse files
committed
[show-hint addon] Use events to notify hint source on open/close/select
Issue #1454
1 parent 9c349a5 commit 14465a5

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

addon/hint/show-hint.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ CodeMirror.showHint = function(cm, getHints, options) {
2929
// When there is only one completion, use it directly.
3030
if (!continued && options.completeSingle !== false && completions.length == 1) {
3131
pickCompletion(cm, data, completions[0]);
32-
if (data.onClose) data.onClose();
32+
CodeMirror.signal(data, "close");
3333
return true;
3434
}
3535

@@ -50,7 +50,7 @@ CodeMirror.showHint = function(cm, getHints, options) {
5050
hints.style.left = left + "px";
5151
hints.style.top = top + "px";
5252
document.body.appendChild(hints);
53-
CodeMirror.signal(cm, "hintShowed");
53+
CodeMirror.signal(data, "shown");
5454

5555
// If we're at the edge of the screen, then we want the menu to appear on the left of the cursor.
5656
var winW = window.innerWidth || Math.max(document.body.offsetWidth, document.documentElement.offsetWidth);
@@ -87,7 +87,7 @@ CodeMirror.showHint = function(cm, getHints, options) {
8787
hints.scrollTop = node.offsetTop - 3;
8888
else if (node.offsetTop + node.offsetHeight > hints.scrollTop + hints.clientHeight)
8989
hints.scrollTop = node.offsetTop + node.offsetHeight - hints.clientHeight + 3;
90-
if (data.onSelect) data.onSelect(completions[selectedHint], node);
90+
CodeMirror.signal(data, "select", completions[selectedHint], node);
9191
}
9292

9393
function screenAmount() {
@@ -154,8 +154,7 @@ CodeMirror.showHint = function(cm, getHints, options) {
154154
cm.off("blur", onBlur);
155155
cm.off("focus", onFocus);
156156
cm.off("scroll", onScroll);
157-
if (willContinue !== true && data.onClose) data.onClose();
158-
CodeMirror.signal(cm, "hintClosed");
157+
if (willContinue !== true) CodeMirror.signal(data, "close");
159158
}
160159
function pick() {
161160
pickCompletion(cm, data, completions[selectedHint]);
@@ -173,7 +172,7 @@ CodeMirror.showHint = function(cm, getHints, options) {
173172
else
174173
once = setTimeout(function(){close(true); continued = true; startHinting();}, 70);
175174
}
176-
if (data.onSelect) data.onSelect(completions[0], hints.firstChild);
175+
CodeMirror.signal(data, "select", completions[0], hints.firstChild);
177176
return true;
178177
}
179178

0 commit comments

Comments
 (0)