mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-12 18:24:03 +02:00
Fix rule INLINE_VOID_TEXTS_AROUND
Added an additional test. Was working previously because the normalization was called several times recursively.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import Schema from '../models/schema'
|
import Schema from '../models/schema'
|
||||||
import Text from '../models/text'
|
import Text from '../models/text'
|
||||||
|
import { List } from 'immutable'
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This module contains the default schema to normalize documents
|
This module contains the default schema to normalize documents
|
||||||
@@ -157,22 +158,32 @@ const INLINE_VOID_TEXTS_AROUND_RULE = {
|
|||||||
const prevNode = index > 0 ? block.nodes.get(index - 1) : null
|
const prevNode = index > 0 ? block.nodes.get(index - 1) : null
|
||||||
const nextNode = block.nodes.get(index + 1)
|
const nextNode = block.nodes.get(index + 1)
|
||||||
|
|
||||||
const prev = (!prevNode || isInlineVoid(prevNode))
|
const prev = !prevNode
|
||||||
const next = (!nextNode || isInlineVoid(nextNode.kind))
|
const next = (!nextNode || isInlineVoid(nextNode))
|
||||||
|
|
||||||
if (next || prev) {
|
if (next || prev) {
|
||||||
accu.push({ next, prev, index })
|
return accu.push({ next, prev, index })
|
||||||
|
} else {
|
||||||
|
return accu
|
||||||
}
|
}
|
||||||
|
}, new List())
|
||||||
|
|
||||||
return accu
|
return !invalids.isEmpty() ? invalids : null
|
||||||
}, [])
|
|
||||||
|
|
||||||
return invalids.length ? invalids : null
|
|
||||||
},
|
},
|
||||||
normalize: (transform, block, invalids) => {
|
normalize: (transform, block, invalids) => {
|
||||||
|
// Shift for every text node inserted previously
|
||||||
|
let shift = 0
|
||||||
|
|
||||||
return invalids.reduce((t, { index, next, prev }) => {
|
return invalids.reduce((t, { index, next, prev }) => {
|
||||||
if (prev) t = transform.insertNodeByKey(block.key, index, Text.create(), { normalize: false })
|
if (prev) {
|
||||||
if (next) t = transform.insertNodeByKey(block.key, index + 1, Text.create(), { normalize: false })
|
t = t.insertNodeByKey(block.key, shift + index, Text.create(), { normalize: false })
|
||||||
|
shift = shift + 1
|
||||||
|
}
|
||||||
|
if (next) {
|
||||||
|
t = t.insertNodeByKey(block.key, shift + index + 1, Text.create(), { normalize: false })
|
||||||
|
shift = shift + 1
|
||||||
|
}
|
||||||
|
|
||||||
return t
|
return t
|
||||||
}, transform)
|
}, transform)
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
export default {}
|
@@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
nodes:
|
||||||
|
- kind: block
|
||||||
|
type: default
|
||||||
|
nodes:
|
||||||
|
- kind: inline
|
||||||
|
isVoid: true
|
||||||
|
type: image
|
||||||
|
- kind: text
|
||||||
|
text: " Hello"
|
||||||
|
- kind: inline
|
||||||
|
isVoid: true
|
||||||
|
type: image
|
||||||
|
- kind: inline
|
||||||
|
isVoid: true
|
||||||
|
type: image
|
@@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
nodes:
|
||||||
|
- kind: block
|
||||||
|
type: default
|
||||||
|
nodes:
|
||||||
|
- kind: text
|
||||||
|
text: ""
|
||||||
|
- kind: inline
|
||||||
|
isVoid: true
|
||||||
|
type: image
|
||||||
|
- kind: text
|
||||||
|
text: " Hello"
|
||||||
|
- kind: inline
|
||||||
|
isVoid: true
|
||||||
|
type: image
|
||||||
|
- kind: text
|
||||||
|
text: ""
|
||||||
|
- kind: inline
|
||||||
|
isVoid: true
|
||||||
|
type: image
|
||||||
|
- kind: text
|
||||||
|
text: ""
|
Reference in New Issue
Block a user