Skip to content

Commit ccacc38

Browse files
committed
[show-hint addon] Resize popup if it doesn't fit in the viewport
Issue #6979
1 parent f143048 commit ccacc38

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

addon/hint/show-hint.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
max-height: 20em;
2121
overflow-y: auto;
22+
box-sizing: border-box;
2223
}
2324

2425
.CodeMirror-hint {

addon/hint/show-hint.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -286,20 +286,14 @@
286286
setTimeout(function() { startScroll = cm.getScrollInfo(); });
287287

288288
var overlapY = box.bottom - winH;
289-
if (overlapY > 0) {
290-
var height = box.bottom - box.top, curTop = pos.top - (pos.bottom - box.top);
291-
if (curTop - height > 0) { // Fits above cursor
292-
hints.style.top = (top = pos.top - height - offsetTop) + "px";
289+
if (overlapY > 0) { // Does not fit below
290+
var height = box.bottom - box.top, spaceAbove = box.top - (pos.bottom - pos.top) - 2
291+
if (winH - box.top < spaceAbove) { // More room at the top
292+
if (height > spaceAbove) hints.style.height = (height = spaceAbove) + "px";
293+
hints.style.top = ((top = pos.top - height) + offsetTop) + "px";
293294
below = false;
294-
} else if (height > winH) {
295-
hints.style.height = (winH - 5) + "px";
296-
hints.style.top = (top = pos.bottom - box.top - offsetTop) + "px";
297-
var cursor = cm.getCursor();
298-
if (data.from.ch != cursor.ch) {
299-
pos = cm.cursorCoords(cursor);
300-
hints.style.left = (left = pos.left - offsetLeft) + "px";
301-
box = hints.getBoundingClientRect();
302-
}
295+
} else {
296+
hints.style.height = (winH - box.top - 2) + "px";
303297
}
304298
}
305299
var overlapX = box.right - winW;

0 commit comments

Comments
 (0)