mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-25 16:20:49 +02:00
Fix rule NO_ADJACENT_TEXT_RULE
This commit is contained in:
@@ -78,7 +78,7 @@ const INLINE_CHILDREN_RULE = {
|
|||||||
const { nodes } = inline
|
const { nodes } = inline
|
||||||
const invalids = nodes.filter(n => n.kind != 'inline' && n.kind != 'text')
|
const invalids = nodes.filter(n => n.kind != 'inline' && n.kind != 'text')
|
||||||
return invalids.size ? invalids : null
|
return invalids.size ? invalids : null
|
||||||
},
|
},
|
||||||
normalize: (transform, inline, invalids) => {
|
normalize: (transform, inline, invalids) => {
|
||||||
return invalids.reduce((t, n) => t.removeNodeByKey(n.key), transform)
|
return invalids.reduce((t, n) => t.removeNodeByKey(n.key), transform)
|
||||||
}
|
}
|
||||||
@@ -98,14 +98,15 @@ const NO_ADJACENT_TEXT_RULE = {
|
|||||||
validate: (node) => {
|
validate: (node) => {
|
||||||
const { nodes } = node
|
const { nodes } = node
|
||||||
const invalids = nodes
|
const invalids = nodes
|
||||||
.filter((n, i) => {
|
|
||||||
const next = nodes.get(i + 1)
|
|
||||||
return n.kind == 'text' && next && next.kind == 'text'
|
|
||||||
})
|
|
||||||
.map((n, i) => {
|
.map((n, i) => {
|
||||||
const next = nodes.get(i + 1)
|
const next = nodes.get(i + 1)
|
||||||
|
if (n.kind !== 'text' || !next || next.kind !== 'text') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
return [n, next]
|
return [n, next]
|
||||||
})
|
})
|
||||||
|
.filter(Boolean)
|
||||||
|
|
||||||
return invalids.size ? invalids : null
|
return invalids.size ? invalids : null
|
||||||
},
|
},
|
||||||
|
@@ -48,6 +48,7 @@ export function applyOperation(transform, operation) {
|
|||||||
const { type } = operation
|
const { type } = operation
|
||||||
const fn = OPERATIONS[type]
|
const fn = OPERATIONS[type]
|
||||||
|
|
||||||
|
console.log('apply op', type, operation);
|
||||||
if (!fn) {
|
if (!fn) {
|
||||||
throw new Error(`Unknown operation type: "${type}".`)
|
throw new Error(`Unknown operation type: "${type}".`)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user