Skip to content
This repository was archived by the owner on Apr 15, 2026. It is now read-only.

Commit 59b1fed

Browse files
committed
Add a test for posAtCoords after the end of a wrapped line
Issue codemirror/dev#1693
1 parent a0a5ed9 commit 59b1fed

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

test/webtest-coords.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,28 @@ describe("EditorView coords", () => {
5555
}
5656
})
5757

58+
const narrow = EditorView.theme({"&": {width: "10em"}})
59+
5860
it("can find coordinates in line-wrapped text", () => {
59-
let cm = tempView("abcd ".repeat(30) + "e", [EditorView.lineWrapping, EditorView.theme({"&": {width: "10em"}})])
61+
let cm = tempView("abcd ".repeat(30) + "e", [EditorView.lineWrapping, narrow])
6062
for (let i = 0; i < cm.state.doc.length; i++) {
6163
let coords = cm.coordsAtPos(i)!
6264
ist(cm.posAtCoords({x: coords.left, y: coords.top + 1}), i)
6365
}
6466
})
6567

68+
it("returns the proper position for coordinates past the end of a wrapped line", () => {
69+
let cm = tempView("abcdef ghijklm nopqr", [EditorView.lineWrapping, narrow])
70+
let p20 = cm.coordsAtPos(20, -1)!
71+
ist(cm.posAtCoords({x: p20.left + 30, y: p20.top + 1}), 20)
72+
})
73+
6674
it("can find coordinates in decorated line-wrapped text", () => {
6775
let d: Range<Decoration>[] = []
6876
for (let i = 0; i < 30; i++) d.push(cls.range(i * 5, i * 5 + 4))
6977
let cm = tempView("abcd ".repeat(30) + "e", [
7078
EditorView.lineWrapping,
71-
EditorView.theme({"&": {width: "10em"}}),
79+
narrow,
7280
deco(...d)
7381
])
7482
for (let i = 0; i < cm.state.doc.length; i++) {
@@ -109,7 +117,7 @@ describe("EditorView coords", () => {
109117
it("can find coordinates in wrapped bidi text", () => {
110118
let cm = tempView("one اثنان three 444 خمسة ".repeat(3), [
111119
EditorView.lineWrapping,
112-
EditorView.theme({"&": {width: "10em"}}),
120+
narrow,
113121
deco(cls.range(0, 3), cls.range(20, 25))
114122
])
115123
for (let i = 0; i < cm.state.doc.length; i++) {

0 commit comments

Comments
 (0)