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

Merge branch 'fix/483' of https://github.com/SamyPesse/slate into fix-empty-inline

This commit is contained in:
Ian Storm Taylor
2016-12-02 10:25:35 -08:00
23 changed files with 47 additions and 19 deletions

View File

@@ -178,13 +178,13 @@ const rules = [
}, },
validate: (node) => { validate: (node) => {
const invalids = node.nodes.reduce((list, child, index) => { const invalids = node.nodes.reduce((list, child, index) => {
if (child.kind == 'block') return list if (child.kind !== 'inline') return list
if (!child.isVoid) return list
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)
// We don't test if "prev" is inline, since it has already been processed in the loop
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.
* *

View File

@@ -3,8 +3,12 @@ nodes:
- kind: block - kind: block
type: default type: default
nodes: nodes:
- kind: text
text: ""
- kind: inline - kind: inline
type: default type: default
nodes: nodes:
- kind: text - kind: text
text: one text: one
- kind: text
text: ""

View File

@@ -3,6 +3,8 @@ nodes:
- kind: block - kind: block
type: default type: default
nodes: nodes:
- kind: text
text: ""
- kind: inline - kind: inline
type: link type: link
nodes: nodes:
@@ -13,3 +15,5 @@ nodes:
isVoid: true isVoid: true
- kind: text - kind: text
text: "" text: ""
- kind: text
text: ""

View File

@@ -0,0 +1,10 @@
nodes:
- kind: block
type: default
nodes:
- kind: inline
type: link
nodes:
- kind: text
text: "Hello"

View File

@@ -0,0 +1,15 @@
nodes:
- kind: block
type: default
nodes:
- kind: text
text: ""
- kind: inline
type: link
nodes:
- kind: text
text: "Hello"
- kind: text
text: ""

View File

@@ -0,0 +1,2 @@
export default {}

View File

@@ -4,11 +4,15 @@ nodes:
- kind: block - kind: block
type: default type: default
nodes: nodes:
- kind: text
text: ""
- kind: inline - kind: inline
type: link type: link
nodes: nodes:
- kind: text - kind: text
text: "Hello " text: "Hello "
- kind: text
text: ""
- kind: inline - kind: inline
isVoid: true isVoid: true
type: image type: image