From 5d9b02cc58f6d4b08db503f40a7a7086ac3c1f41 Mon Sep 17 00:00:00 2001 From: Alexander Bulychev Date: Tue, 26 Dec 2023 15:32:07 +0400 Subject: [PATCH] Cleanup --- modules/clipboard.js | 21 ++++++++++++++------- modules/multiline.js | 4 ++-- test/functional/list.ts | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/modules/clipboard.js b/modules/clipboard.js index 00f209a8a9..06d88d1957 100644 --- a/modules/clipboard.js +++ b/modules/clipboard.js @@ -398,23 +398,30 @@ function traverse(scroll, node, elementMatchers, textMatchers, nodeMatches) { textMatchers, nodeMatches, ); - if (childNode.nodeType === node.ELEMENT_NODE) { - const isNextNodeList = idx < allNodes.length - 2 - && allNodes[idx + 2].nodeType === node.ELEMENT_NODE - && ['ul', 'ol'].indexOf(allNodes[idx + 2].tagName.toLowerCase()) > -1; - const forceNewLine = childNode.tagName.toLowerCase() === 'br' && isNextNodeList; + const nextNode = idx < allNodes.length - 1 && allNodes[idx + 1]; + const isNextNodeList = nextNode + && nextNode.nodeType === node.ELEMENT_NODE + && ['ul', 'ol'].indexOf(nextNode.tagName.toLowerCase()) > -1; + if (childNode.nodeType === node.ELEMENT_NODE) { childrenDelta = elementMatchers.reduce((reducedDelta, matcher) => { return matcher(childNode, reducedDelta, scroll); }, childrenDelta); childrenDelta = (nodeMatches.get(childNode) || []).reduce( (reducedDelta, matcher) => { - return matcher(childNode, reducedDelta, scroll, forceNewLine); + return matcher(childNode, reducedDelta, scroll); }, childrenDelta, ); } - return delta.concat(childrenDelta); + + const newDelta = delta.concat(childrenDelta); + + if (isNextNodeList) { + newDelta.insert('\n'); + } + + return newDelta; }, new Delta()); } return new Delta(); diff --git a/modules/multiline.js b/modules/multiline.js index 60a86acf18..eee51f4d1c 100644 --- a/modules/multiline.js +++ b/modules/multiline.js @@ -3,8 +3,8 @@ import Quill from '../core/quill'; import MultilineBreak from '../blots/multiline_break'; import Module from '../core/module'; -function breakMatcher(node, reducedDelta, scroll, forceNewLine) { - if (!(node.nextSibling || node.previousSibling) || forceNewLine) { +function breakMatcher(node) { + if (!(node.nextSibling || node.previousSibling)) { return new Delta().insert('\n'); } return new Delta().insert({ multilineBreak: '' }); diff --git a/test/functional/list.ts b/test/functional/list.ts index 147ec3820f..45ce5cfb99 100644 --- a/test/functional/list.ts +++ b/test/functional/list.ts @@ -12,7 +12,7 @@ test('multiline break before list should not merge with the 1st list item (T1206 await t.expect(tableContent.replace(/\s/g, '')) .eql(` -

Test Headline

+

Test Headline

  1. First
  2. Second