Skip to content
This repository was archived by the owner on Apr 16, 2026. It is now read-only.

Commit b37017c

Browse files
committed
[show-hint addon] More careful positioning of pop-up
1 parent b3c2ecd commit b37017c

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

addon/hint/show-hint.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,26 @@ CodeMirror.showHint = function(cm, getHints, options) {
3030

3131
// If we're at the edge of the screen, then we want the menu to appear on the left of the cursor.
3232
var winW = window.innerWidth || Math.max(document.body.offsetWidth, document.documentElement.offsetWidth);
33-
if (winW - pos.left < hints.clientWidth)
34-
hints.style.left = (pos.left - sel.clientWidth) + "px";
33+
var winH = window.innerHeight || Math.max(document.body.offsetHeight, document.documentElement.offsetHeight);
34+
var box = hints.getBoundingClientRect();
35+
var overlapX = box.right - winW, overlapY = box.bottom - winH;
36+
if (overlapX > 0) {
37+
if (box.right - box.left > winW) {
38+
hints.style.width = (winW - 5) + "px";
39+
overlapX -= (box.right - box.left) - winW;
40+
}
41+
hints.style.left = (pos.left - overlapX) + "px";
42+
}
43+
if (overlapY > 0) {
44+
var height = box.bottom - box.top;
45+
if (box.top - (pos.bottom - pos.top) - height > 0) {
46+
overlapY = height + (pos.bottom - pos.top);
47+
} else if (height > winH) {
48+
hints.style.height = (winH - 5) + "px";
49+
overlapY -= height - winH;
50+
}
51+
hints.style.top = (pos.bottom - overlapY) + "px";
52+
}
3553

3654
function changeActive(i) {
3755
if (i < 0 || i >= completions.length || selectedHint == i) return;

0 commit comments

Comments
 (0)