1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-17 20:51:20 +02:00

Fix Edge positioning with newlines (#2622)

* Fix Edge positioning with newlines

Edge has a [bug][1] where `Range.prototype.toString()` will convert `\n`
into `\r\n`. The bug causes a loop when slate-react attempts to
reposition its cursor to match the native position.

This change avoids calling `Range.prototype.toString()` by cloning the
content nodes and measuring `textContent` on those instead.

[1]: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10291116/

* Add COMPAT message
This commit is contained in:
Jason Staten
2019-03-07 16:01:59 -07:00
committed by Ian Storm Taylor
parent bc8de50d99
commit 4d0ccc8e81

View File

@@ -51,7 +51,12 @@ function findPoint(nativeNode, nativeOffset, editor) {
range.setStart(textNode, 0) range.setStart(textNode, 0)
range.setEnd(nearestNode, nearestOffset) range.setEnd(nearestNode, nearestOffset)
node = textNode node = textNode
offset = range.toString().length
// COMPAT: Edge has a bug where Range.prototype.toString() will convert \n
// into \r\n. The bug causes a loop when slate-react attempts to reposition
// its cursor to match the native position. Use textContent.length instead.
// https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10291116/
offset = range.cloneContents().textContent.length
} else { } else {
// For void nodes, the element with the offset key will be a cousin, not an // For void nodes, the element with the offset key will be a cousin, not an
// ancestor, so find it by going down from the nearest void parent. // ancestor, so find it by going down from the nearest void parent.