Skip to content

Commit

Permalink
fix: do not show the datatip when the mouse is too far away from a token
Browse files Browse the repository at this point in the history
  • Loading branch information
robertrossmann committed Mar 15, 2019
1 parent ba3fb04 commit 793321e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/datatip-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,22 @@ module.exports = class DatatipManager {
const component = this.editorView.getComponent();
// the screen position returned here is always capped to the max width of the text in this row
const screenPosition = component.screenPositionForMouseEvent(evt);
// the coordinates below represent X and Y positions on the screen of where the mouse event
// occured and where the capped screenPosition is located
const coordinates = {
mouse: component.pixelPositionForMouseEvent(evt),
screen: component.pixelPositionForScreenPosition(screenPosition),
};
const distance = Math.abs(coordinates.mouse.left - coordinates.screen.left);

// If the distance between the coordinates is greater than the default character width, it
// means the mouse event occured quite far away from where the text ends on that row. Do not
// show the datatip in such situations and hide any existing datatips (the mouse moved more to
// the right, away from the actual text)
if (distance >= this.editor.getDefaultCharWidth()) {
return this.hideDataTip();
}

const point = this.editor.bufferPositionForScreenPosition(screenPosition);
if ((this.currentMarkerRange === null) ||
(!this.currentMarkerRange.containsPoint(point))) {
Expand Down

0 comments on commit 793321e

Please sign in to comment.