Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Bulychev committed Dec 26, 2023
1 parent 43becfc commit 5d9b02c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
21 changes: 14 additions & 7 deletions modules/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions modules/multiline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '' });
Expand Down
2 changes: 1 addition & 1 deletion test/functional/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
<p>Test Headline<br></p>
<p>Test Headline<br><br></p>
<ol>
<li><span class="ql-ui" contenteditable="false"></span>First</li>
<li><span class="ql-ui" contenteditable="false"></span>Second</li>
Expand Down

0 comments on commit 5d9b02c

Please sign in to comment.