mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-29 09:59:48 +02:00
Fallback to last leaf node when inserting change (#1359)
This commit is contained in:
committed by
Ian Storm Taylor
parent
cfa8cf6834
commit
6dc3c6441c
@@ -428,25 +428,25 @@ function AfterPlugin() {
|
|||||||
// Get the text node and leaf in question.
|
// Get the text node and leaf in question.
|
||||||
const { document, selection } = value
|
const { document, selection } = value
|
||||||
const node = document.getDescendant(point.key)
|
const node = document.getDescendant(point.key)
|
||||||
|
const block = document.getClosestBlock(node.key)
|
||||||
const leaves = node.getLeaves()
|
const leaves = node.getLeaves()
|
||||||
|
const lastText = block.getLastText()
|
||||||
|
const lastLeaf = leaves.last()
|
||||||
let start = 0
|
let start = 0
|
||||||
let end = 0
|
let end = 0
|
||||||
|
|
||||||
const leaf = leaves.find((r) => {
|
const leaf = leaves.find((r) => {
|
||||||
|
start = end
|
||||||
end += r.text.length
|
end += r.text.length
|
||||||
if (end >= point.offset) return true
|
if (end >= point.offset) return true
|
||||||
start = end
|
}) || lastLeaf
|
||||||
})
|
|
||||||
|
|
||||||
// Get the text information.
|
// Get the text information.
|
||||||
const { text } = leaf
|
const { text } = leaf
|
||||||
let { textContent } = anchorNode
|
let { textContent } = anchorNode
|
||||||
const block = document.getClosestBlock(node.key)
|
|
||||||
const lastText = block.getLastText()
|
|
||||||
const lastLeaf = leaves.last()
|
|
||||||
const lastChar = textContent.charAt(textContent.length - 1)
|
|
||||||
const isLastText = node == lastText
|
const isLastText = node == lastText
|
||||||
const isLastLeaf = leaf == lastLeaf
|
const isLastLeaf = leaf == lastLeaf
|
||||||
|
const lastChar = textContent.charAt(textContent.length - 1)
|
||||||
|
|
||||||
// COMPAT: If this is the last leaf, and the DOM text ends in a new line,
|
// COMPAT: If this is the last leaf, and the DOM text ends in a new line,
|
||||||
// we will have added another new line in <Leaf>'s render method to account
|
// we will have added another new line in <Leaf>'s render method to account
|
||||||
|
Reference in New Issue
Block a user