[lint addon] Make sure tooltips don't stick out of the window width

Issue https://github.com/codemirror/codemirror5/pull/7044
This commit is contained in:
Marijn Haverbeke 2023-07-21 21:23:28 +02:00
parent 82ce3d2f64
commit 370f7c4a72
1 changed files with 4 additions and 2 deletions

View File

@ -24,8 +24,10 @@
function position(e) {
if (!tt.parentNode) return CodeMirror.off(document, "mousemove", position);
tt.style.top = Math.max(0, e.clientY - tt.offsetHeight - 5) + "px";
tt.style.left = (e.clientX + 5) + "px";
var top = Math.max(0, e.clientY - tt.offsetHeight - 5);
var left = Math.max(0, Math.min(e.clientX + 5, tt.ownerDocument.defaultView.innerWidth - tt.offsetWidth));
tt.style.top = top + "px"
tt.style.left = left + "px";
}
CodeMirror.on(document, "mousemove", position);
position(e);