mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-01 04:50:27 +02:00
Adapt schema to add empty text nodes around all inlines
This commit is contained in:
@@ -184,7 +184,7 @@ const rules = [
|
|||||||
const prev = index > 0 ? node.nodes.get(index - 1) : null
|
const prev = index > 0 ? node.nodes.get(index - 1) : null
|
||||||
const next = node.nodes.get(index + 1)
|
const next = node.nodes.get(index + 1)
|
||||||
const insertBefore = !prev
|
const insertBefore = !prev
|
||||||
const insertAfter = !next || isInlineVoid(next)
|
const insertAfter = !next || (next.kind == 'inline')
|
||||||
|
|
||||||
if (insertAfter || insertBefore) {
|
if (insertAfter || insertBefore) {
|
||||||
list = list.push({ insertAfter, insertBefore, index })
|
list = list.push({ insertAfter, insertBefore, index })
|
||||||
@@ -267,13 +267,13 @@ const rules = [
|
|||||||
const next = nodes.get(i + 1)
|
const next = nodes.get(i + 1)
|
||||||
|
|
||||||
// If it's the first node, and the next is a void, preserve it.
|
// If it's the first node, and the next is a void, preserve it.
|
||||||
if (!prev && isInlineVoid(next)) return
|
if (!prev && next.kind == 'inline') return
|
||||||
|
|
||||||
// It it's the last node, and the previous is a void, preserve it.
|
// It it's the last node, and the previous is an inline, preserve it.
|
||||||
if (!next && isInlineVoid(prev)) return
|
if (!next && prev.kind == 'inline') return
|
||||||
|
|
||||||
// If it's surrounded by voids, preserve it.
|
// If it's surrounded by inlines, preserve it.
|
||||||
if (next && prev && isInlineVoid(next) && isInlineVoid(prev)) return
|
if (next && prev && next.kind == 'inline' && prev.kind == 'inline') return
|
||||||
|
|
||||||
// Otherwise, remove it.
|
// Otherwise, remove it.
|
||||||
return true
|
return true
|
||||||
@@ -290,17 +290,6 @@ const rules = [
|
|||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
/**
|
|
||||||
* Test if a `node` is an inline void node.
|
|
||||||
*
|
|
||||||
* @param {Node} node
|
|
||||||
* @return {Boolean}
|
|
||||||
*/
|
|
||||||
|
|
||||||
function isInlineVoid(node) {
|
|
||||||
return (node.kind == 'inline' && node.isVoid)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the core schema.
|
* Create the core schema.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user