Skip to content

Commit 7ce264f

Browse files
committed
[show-hint addon] Close hinting popup when scrolled out of view
1 parent c69ce2e commit 7ce264f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

addon/hint/show-hint.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ CodeMirror.showHint = function(cm, getHints, options) {
3131
elt.hintId = i;
3232
}
3333
var pos = cm.cursorCoords(options.alignWithWord !== false ? data.from : null);
34-
var left = pos.left, top = pos.bottom;
34+
var left = pos.left, top = pos.bottom, below = true;
3535
hints.style.left = left + "px";
3636
hints.style.top = top + "px";
3737
document.body.appendChild(hints);
@@ -52,6 +52,7 @@ CodeMirror.showHint = function(cm, getHints, options) {
5252
var height = box.bottom - box.top;
5353
if (box.top - (pos.bottom - pos.top) - height > 0) {
5454
overlapY = height + (pos.bottom - pos.top);
55+
below = false;
5556
} else if (height > winH) {
5657
hints.style.height = (winH - 5) + "px";
5758
overlapY -= height - winH;
@@ -101,8 +102,11 @@ CodeMirror.showHint = function(cm, getHints, options) {
101102
cm.on("focus", onFocus);
102103
var startScroll = cm.getScrollInfo();
103104
function onScroll() {
104-
var curScroll = cm.getScrollInfo();
105-
hints.style.top = (top + startScroll.top - curScroll.top) + "px";
105+
var curScroll = cm.getScrollInfo(), editor = cm.getWrapperElement().getBoundingClientRect();
106+
var newTop = top + startScroll.top - curScroll.top, point = newTop;
107+
if (!below) point += hints.offsetHeight;
108+
if (point <= editor.top || point >= editor.bottom) return close();
109+
hints.style.top = newTop + "px";
106110
hints.style.left = (left + startScroll.left - curScroll.left) + "px";
107111
}
108112
cm.on("scroll", onScroll);

0 commit comments

Comments
 (0)