Skip to content

Commit 79de1d1

Browse files
Merge pull request #22 from robertrossmann/fix/datatip-sensitivity
fix: do not show the datatip when the mouse is too far away from a token
2 parents ba3fb04 + 793321e commit 79de1d1

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

lib/datatip-manager.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,22 @@ module.exports = class DatatipManager {
257257
const component = this.editorView.getComponent();
258258
// the screen position returned here is always capped to the max width of the text in this row
259259
const screenPosition = component.screenPositionForMouseEvent(evt);
260+
// the coordinates below represent X and Y positions on the screen of where the mouse event
261+
// occured and where the capped screenPosition is located
262+
const coordinates = {
263+
mouse: component.pixelPositionForMouseEvent(evt),
264+
screen: component.pixelPositionForScreenPosition(screenPosition),
265+
};
266+
const distance = Math.abs(coordinates.mouse.left - coordinates.screen.left);
267+
268+
// If the distance between the coordinates is greater than the default character width, it
269+
// means the mouse event occured quite far away from where the text ends on that row. Do not
270+
// show the datatip in such situations and hide any existing datatips (the mouse moved more to
271+
// the right, away from the actual text)
272+
if (distance >= this.editor.getDefaultCharWidth()) {
273+
return this.hideDataTip();
274+
}
275+
260276
const point = this.editor.bufferPositionForScreenPosition(screenPosition);
261277
if ((this.currentMarkerRange === null) ||
262278
(!this.currentMarkerRange.containsPoint(point))) {

0 commit comments

Comments
 (0)