Skip to content

Commit 49799f4

Browse files
committed
Update match tooltip when expression changes.
1 parent 8a442e2 commit 49799f4

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

dev/src/views/TextHover.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,43 @@ export default class TextHover {
2424
constructor (editor, highlighter) {
2525
this.editor = editor;
2626
this.highlighter = highlighter;
27-
this.matches = null;
27+
this._matches = this._x = null;
2828

2929
let o = editor.display.lineDiv;
3030
o.addEventListener("mousemove", (evt)=> this._handleMouseMove(evt));
3131
o.addEventListener("mouseout", (evt)=> this._handleMouseOut(evt));
3232
}
3333

34+
set matches(val) {
35+
this._matches = val;
36+
this._update();
37+
}
3438

3539
// private methods:
3640
_handleMouseMove(evt) {
37-
let index, cm = this.editor, match, matches = this.matches;
41+
this._x = evt.clientX;
42+
this._y = evt.clientY + window.pageYOffset;
43+
this._update();
44+
}
45+
46+
_handleMouseOut(evt) {
47+
this._x = null;
48+
this._update();
49+
}
50+
51+
_update() {
52+
if (this._x === null) {
53+
this.highlighter.hoverMatch = null;
54+
app.tooltip.hover.hide("TextHover");
55+
return;
56+
}
57+
let index, cm = this.editor, match, matches = this._matches, x = this._x, y = this._y;
3858

39-
if (matches && matches.length && (index = CMUtils.getCharIndexAt(cm, evt.clientX, evt.clientY + window.pageYOffset)) != null) {
59+
if (matches && matches.length && (index = CMUtils.getCharIndexAt(cm, x, y)) != null) {
4060
match = this.highlighter.hoverMatch = app.text.getMatchAt(index);
4161
}
4262
let rect = (index != null) && CMUtils.getCharRect(cm, index);
43-
if (rect) { rect.right = rect.left = evt.clientX; }
44-
app.tooltip.hover.show("TextHover", app.reference.tipForMatch(match, cm.getValue()), evt.clientX, rect.bottom, true, 0);
45-
}
46-
47-
_handleMouseOut(evt) {
48-
this.highlighter.hoverMatch = null;
49-
app.tooltip.hover.hide("TextHover");
63+
if (rect) { rect.right = rect.left = x; }
64+
app.tooltip.hover.show("TextHover", app.reference.tipForMatch(match, cm.getValue()), x, rect.bottom, true, 0);
5065
}
5166
}

0 commit comments

Comments
 (0)