Skip to content

Commit

Permalink
Make posFromCaret ignore zero-size rectangles
Browse files Browse the repository at this point in the history
FIX: Fix an issue where `display: content` elements could break `posAtCoords`.

Issue #177
  • Loading branch information
marijnh committed Dec 11, 2024
1 parent 0656cdd commit bbd0ab2
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/domcoords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,11 @@ function posFromCaret(view: EditorView, node: Node, offset: number, coords: {top
let outsideBlock = -1
for (let cur = node, sawBlock = false;;) {
if (cur == view.dom) break
let desc = view.docView.nearestDesc(cur, true)
let desc = view.docView.nearestDesc(cur, true), rect
if (!desc) return null
if (desc.dom.nodeType == 1 && (desc.node.isBlock && desc.parent || !desc.contentDOM)) {
let rect = (desc.dom as HTMLElement).getBoundingClientRect()
if (desc.dom.nodeType == 1 && (desc.node.isBlock && desc.parent || !desc.contentDOM) &&
// Ignore elements with zero-size bounding rectangles
((rect = (desc.dom as HTMLElement).getBoundingClientRect()).width || rect.height)) {
if (desc.node.isBlock && desc.parent) {
// Only apply the horizontal test to the innermost block. Vertical for any parent.
if (!sawBlock && rect.left > coords.left || rect.top > coords.top) outsideBlock = desc.posBefore
Expand Down

0 comments on commit bbd0ab2

Please sign in to comment.