Skip to content

Commit 9af1fca

Browse files
committed
Disable expression highlighting / tooltips when the mouse is down.
This is both to improve UX & to work around an issue with IE introduced in CodeMirror 3.22. Signed-off-by: Grant Skinner <[email protected]>
1 parent 5515bf8 commit 9af1fca

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

js/ExpressionHover.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ SOFTWARE.
3434
p.highlighter = null;
3535
p.token = null;
3636
p.offset = 0;
37+
p.isMouseDown = false;
3738

3839
p.initialize = function(cm, highlighter) {
3940
this.cm = cm;
@@ -43,20 +44,35 @@ SOFTWARE.
4344
this.tooltip = Tooltip.add(cm.display.lineDiv);
4445
this.tooltip.on("mousemove", this.onMouseMove, this);
4546
this.tooltip.on("mouseout", this.onMouseOut, this);
47+
48+
cm.on("mousedown", $.bind(this, this.onMouseDown));
49+
};
50+
51+
p.onMouseDown = function(evt) {
52+
if (evt.which != 1) { return; }
53+
this.onMouseMove(); // clear current
54+
this.isMouseDown = true;
55+
(window.addEventListener ? window : document).addEventListener("mouseup", $.bind(this, this.onMouseUp));
56+
};
57+
58+
p.onMouseUp = function(evt) {
59+
if (evt.which != 1) { return; }
60+
this.isMouseDown = false;
4661
};
4762

4863
p.onMouseMove = function(evt) {
64+
if (this.isMouseDown) { return; }
4965
var index, cm=this.cm, token=this.token, target = null;
5066

51-
if (token && (index = CMUtils.getCharIndexAt(cm, evt.clientX, evt.clientY+window.pageYOffset)) != null) {
67+
if (evt && token && (index = CMUtils.getCharIndexAt(cm, evt.clientX, evt.clientY+window.pageYOffset)) != null) {
5268
index -= this.offset;
5369
while (token) {
5470
if (index >= token.i && index < token.end) { target = token; break; }
5571
token = token.next;
5672
}
5773
}
5874
if (target && target.proxy) { target = target.proxy; }
59-
75+
6076
this.highlighter.selectToken(target);
6177
var rect = (index != null) && CMUtils.getCharRect(cm, index);
6278
if (rect) { rect.right = rect.left = evt.clientX; }

0 commit comments

Comments
 (0)