Skip to content

Commit

Permalink
Include arrow's vertical extent when checking whether the pointer is …
Browse files Browse the repository at this point in the history
…over a tooltip

FIX: Make it easier to move the pointer over a hover tooltip with an arrow by
not closing the tooltip when the pointer is moving over the gap for the arrow.

Issue codemirror/dev#1423
  • Loading branch information
marijnh committed Aug 12, 2024
1 parent d7ac939 commit b58ff33
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -723,9 +723,14 @@ class HoverPlugin {
const tooltipMargin = 4

function isInTooltip(tooltip: HTMLElement, event: MouseEvent) {
let rect = tooltip.getBoundingClientRect()
return event.clientX >= rect.left - tooltipMargin && event.clientX <= rect.right + tooltipMargin &&
event.clientY >= rect.top - tooltipMargin && event.clientY <= rect.bottom + tooltipMargin
let {left, right, top, bottom} = tooltip.getBoundingClientRect(), arrow
if (arrow = tooltip.querySelector(".cm-tooltip-arrow")) {
let arrowRect = arrow.getBoundingClientRect()
top = Math.min(arrowRect.top, top)
bottom = Math.max(arrowRect.bottom, bottom)
}
return event.clientX >= left - tooltipMargin && event.clientX <= right + tooltipMargin &&
event.clientY >= top - tooltipMargin && event.clientY <= bottom + tooltipMargin
}

function isOverRange(view: EditorView, from: number, to: number, x: number, y: number, margin: number) {
Expand Down

0 comments on commit b58ff33

Please sign in to comment.