Skip to content

Commit

Permalink
Extract node removal function and helper in cleditHighlighter
Browse files Browse the repository at this point in the history
Replaces comments and follows example of `highlight/1` in same file
  • Loading branch information
yakryder committed Oct 9, 2019
1 parent 79c244a commit 7bb112f
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/services/editor/cledit/cleditHighlighter.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,22 @@ function Highlighter(editor) {
contentElt.appendChild(newSectionEltList);
}

// Remove unauthorized nodes (text nodes outside of sections or
// duplicated sections via copy/paste)
let childNode = contentElt.firstChild;
while (childNode) {
const nextNode = childNode.nextSibling;
if (!childNode.section) {
contentElt.removeChild(childNode);
const lacksSection = node => !node.section;

const removeUnauthorizedChildNodesFrom = (parentNode) => {
let childNode = parentNode.firstChild;
while (childNode) {
const nextNode = childNode.nextSibling;
if (lacksSection(childNode)) {
parentNode.removeChild(childNode);
}
childNode = nextNode;
}
childNode = nextNode;
}
this.addTrailingNode();
this.$trigger('highlighted');
this.addTrailingNode();
this.$trigger('highlighted');
};

removeUnauthorizedChildNodesFrom(contentElt);

if (editor.selectionMgr.hasFocus()) {
editor.selectionMgr.restoreSelection();
Expand Down

0 comments on commit 7bb112f

Please sign in to comment.