Skip to content

Commit 19f9274

Browse files
committed
Add fixedTooltip option for linter addon
1 parent e748901 commit 19f9274

1 file changed

Lines changed: 28 additions & 16 deletions

File tree

addon/lint/lint.js

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"use strict";
1313
var GUTTER_ID = "CodeMirror-lint-markers";
1414

15-
function showTooltip(cm, e, content) {
15+
function showTooltip(cm, e, content, node) {
1616
var tt = document.createElement("div");
1717
tt.className = "CodeMirror-lint-tooltip cm-s-" + cm.options.theme;
1818
tt.appendChild(content.cloneNode(true));
@@ -21,13 +21,21 @@
2121
else
2222
document.body.appendChild(tt);
2323

24-
function position(e) {
25-
if (!tt.parentNode) return CodeMirror.off(document, "mousemove", position);
26-
tt.style.top = Math.max(0, e.clientY - tt.offsetHeight - 5) + "px";
27-
tt.style.left = (e.clientX + 5) + "px";
24+
if (cm.state.lint.options.fixedTooltip) {
25+
const { top, left } = node.getBoundingClientRect()
26+
27+
tt.style.top = top - 5 + 'px'
28+
tt.style.left = left + 20 + 'px'
29+
} else {
30+
function position(e) {
31+
if (!tt.parentNode) return CodeMirror.off(document, "mousemove", position);
32+
tt.style.top = Math.max(0, e.clientY - tt.offsetHeight - 5) + "px";
33+
tt.style.left = (e.clientX + 5) + "px";
34+
}
35+
CodeMirror.on(document, "mousemove", position);
36+
position(e);
2837
}
29-
CodeMirror.on(document, "mousemove", position);
30-
position(e);
38+
3139
if (tt.style.opacity != null) tt.style.opacity = 1;
3240
return tt;
3341
}
@@ -42,19 +50,23 @@
4250
}
4351

4452
function showTooltipFor(cm, e, content, node) {
45-
var tooltip = showTooltip(cm, e, content);
53+
var tooltip = showTooltip(cm, e, content, node);
4654
function hide() {
4755
CodeMirror.off(node, "mouseout", hide);
4856
if (tooltip) { hideTooltip(tooltip); tooltip = null; }
4957
}
50-
var poll = setInterval(function() {
51-
if (tooltip) for (var n = node;; n = n.parentNode) {
52-
if (n && n.nodeType == 11) n = n.host;
53-
if (n == document.body) return;
54-
if (!n) { hide(); break; }
55-
}
56-
if (!tooltip) return clearInterval(poll);
57-
}, 400);
58+
59+
if (!cm.state.lint.options.fixedTooltip) {
60+
var poll = setInterval(function() {
61+
if (tooltip) for (var n = node;; n = n.parentNode) {
62+
if (n && n.nodeType == 11) n = n.host;
63+
if (n == document.body) return;
64+
if (!n) { hide(); break; }
65+
}
66+
if (!tooltip) return clearInterval(poll);
67+
}, 400);
68+
}
69+
5870
CodeMirror.on(node, "mouseout", hide);
5971
}
6072

0 commit comments

Comments
 (0)