From 808ae3c1fbd799306a190faeeefe397af51541cf Mon Sep 17 00:00:00 2001 From: Samy Pesse Date: Tue, 18 Oct 2016 22:43:18 +0200 Subject: [PATCH] Fix rule NO_ADJACENT_TEXT_RULE --- src/plugins/schema.js | 11 ++++++----- src/transforms/apply-operation.js | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/plugins/schema.js b/src/plugins/schema.js index cbc462f57..cf24a1b74 100644 --- a/src/plugins/schema.js +++ b/src/plugins/schema.js @@ -78,7 +78,7 @@ const INLINE_CHILDREN_RULE = { const { nodes } = inline const invalids = nodes.filter(n => n.kind != 'inline' && n.kind != 'text') return invalids.size ? invalids : null - }, +}, normalize: (transform, inline, invalids) => { return invalids.reduce((t, n) => t.removeNodeByKey(n.key), transform) } @@ -98,14 +98,15 @@ const NO_ADJACENT_TEXT_RULE = { validate: (node) => { const { nodes } = node const invalids = nodes - .filter((n, i) => { - const next = nodes.get(i + 1) - return n.kind == 'text' && next && next.kind == 'text' - }) .map((n, i) => { const next = nodes.get(i + 1) + if (n.kind !== 'text' || !next || next.kind !== 'text') { + return + } + return [n, next] }) + .filter(Boolean) return invalids.size ? invalids : null }, diff --git a/src/transforms/apply-operation.js b/src/transforms/apply-operation.js index 5cc8dd70d..167279950 100644 --- a/src/transforms/apply-operation.js +++ b/src/transforms/apply-operation.js @@ -48,6 +48,7 @@ export function applyOperation(transform, operation) { const { type } = operation const fn = OPERATIONS[type] + console.log('apply op', type, operation); if (!fn) { throw new Error(`Unknown operation type: "${type}".`) }