Skip to content

Commit

Permalink
Prevent the cursor from being rendered on the wrong side of a block w…
Browse files Browse the repository at this point in the history
…idget

FIX: Fix an issue that could cause the cursor to be rendered on the wrong side of
a zero-length block widget.
  • Loading branch information
marijnh committed Apr 27, 2024
1 parent 70ebd2a commit e5cb635
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/docview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,9 @@ export class DocView extends ContentView {
(!best || child instanceof LineView && !(best instanceof LineView && side >= 0))) {
best = child
bestPos = start
} else if (best && start == pos && end == pos && child instanceof BlockWidgetView && Math.abs(side) < 2) {
if (child.deco.startSide < 0) break
else if (i) best = null
}
off = start
}
Expand Down
12 changes: 8 additions & 4 deletions test/webtest-coords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ describe("EditorView coords", () => {
let cm = tempView("ab", [deco(widget.range(0), widget.range(1), widget.range(2))])
let sides = Array.from(cm.contentDOM.querySelectorAll(".widget")).map(w => w.getBoundingClientRect().top)
ist(near(cm.coordsAtPos(0, -1)!.bottom, sides[0]))
ist(near(cm.coordsAtPos(0, 1)!.bottom, sides[1]))
ist(near(cm.coordsAtPos(0, 1)!.bottom, sides[0]))
ist(near(cm.coordsAtPos(0, 2 as any)!.bottom, sides[1]))
ist(near(cm.coordsAtPos(1, -1)!.bottom, sides[1]))
ist(near(cm.coordsAtPos(1, 1)!.bottom, sides[2]))
ist(near(cm.coordsAtPos(1, 1)!.bottom, sides[1]))
ist(near(cm.coordsAtPos(1, 2 as any)!.bottom, sides[2]))
ist(near(cm.coordsAtPos(2, -1)!.bottom, sides[2]))
ist(near(cm.coordsAtPos(2, 1)!.bottom, sides[2]))
})
Expand All @@ -118,9 +120,11 @@ describe("EditorView coords", () => {
let sides = Array.prototype.map.call(cm.contentDOM.querySelectorAll(".widget"), w => w.getBoundingClientRect().bottom)
ist(near(cm.coordsAtPos(0, -1)!.top, sides[0]))
ist(near(cm.coordsAtPos(0, 1)!.top, sides[0]))
ist(near(cm.coordsAtPos(1, -1)!.top, sides[0]))
ist(near(cm.coordsAtPos(1, -1)!.top, sides[1]))
ist(near(cm.coordsAtPos(1, -2 as any)!.top, sides[0]))
ist(near(cm.coordsAtPos(1, 1)!.top, sides[1]))
ist(near(cm.coordsAtPos(2, -1)!.top, sides[1]))
ist(near(cm.coordsAtPos(2, -1)!.top, sides[2]))
ist(near(cm.coordsAtPos(2, -2 as any)!.top, sides[1]))
ist(near(cm.coordsAtPos(2, 1)!.top, sides[2]))
})

Expand Down

0 comments on commit e5cb635

Please sign in to comment.