Skip to content

Commit e073114

Browse files
committed
fix(cursor): Fix block focus events when using a browser zoom. There were rounding issues
Safari still has an issue with newlines at the end of an html element. This doesn't work: ```html <p> Hello </p> <p> World </p> ``` And this is working: ```html <p>Hello</p> <p>World</p> ```
1 parent ad5e433 commit e073114

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/cursor.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export default class Cursor {
9696
hostRange.collapse(false)
9797
const hostCoords = getRangeBoundingClientRect(hostRange, this.win)
9898
const cursorCoords = getRangeBoundingClientRect(this.range.nativeRange, this.win)
99-
return hostCoords.bottom === cursorCoords.bottom
99+
return isCloseTo(hostCoords.bottom, cursorCoords.bottom)
100100
}
101101

102102
isAtFirstLine () {
@@ -105,7 +105,7 @@ export default class Cursor {
105105
hostRange.collapse(true)
106106
const hostCoords = getRangeBoundingClientRect(hostRange, this.win)
107107
const cursorCoords = getRangeBoundingClientRect(this.range.nativeRange, this.win)
108-
return hostCoords.top === cursorCoords.top
108+
return isCloseTo(hostCoords.top, cursorCoords.top)
109109
}
110110

111111
isAtBeginning () {
@@ -368,3 +368,9 @@ function getRangeBoundingClientRect (range, win) {
368368
el.remove()
369369
return coords
370370
}
371+
372+
function isCloseTo (a, b) {
373+
if (a === b) return true
374+
if (Math.abs(a - b) <= 2) return true
375+
return false
376+
}

0 commit comments

Comments
 (0)