|
12 | 12 | "use strict"; |
13 | 13 | var GUTTER_ID = "CodeMirror-lint-markers"; |
14 | 14 |
|
15 | | - function showTooltip(cm, e, content) { |
| 15 | + function showTooltip(cm, e, content, node) { |
16 | 16 | var tt = document.createElement("div"); |
17 | 17 | tt.className = "CodeMirror-lint-tooltip cm-s-" + cm.options.theme; |
18 | 18 | tt.appendChild(content.cloneNode(true)); |
|
21 | 21 | else |
22 | 22 | document.body.appendChild(tt); |
23 | 23 |
|
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); |
28 | 37 | } |
29 | | - CodeMirror.on(document, "mousemove", position); |
30 | | - position(e); |
| 38 | + |
31 | 39 | if (tt.style.opacity != null) tt.style.opacity = 1; |
32 | 40 | return tt; |
33 | 41 | } |
|
42 | 50 | } |
43 | 51 |
|
44 | 52 | function showTooltipFor(cm, e, content, node) { |
45 | | - var tooltip = showTooltip(cm, e, content); |
| 53 | + var tooltip = showTooltip(cm, e, content, node); |
46 | 54 | function hide() { |
47 | 55 | CodeMirror.off(node, "mouseout", hide); |
48 | 56 | if (tooltip) { hideTooltip(tooltip); tooltip = null; } |
49 | 57 | } |
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 | + |
58 | 70 | CodeMirror.on(node, "mouseout", hide); |
59 | 71 | } |
60 | 72 |
|
|
0 commit comments