Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method extraction cledithighlighter #1558

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Extract node removal function and helper in cleditHighlighter
Replaces comments and follows example of `highlight/1` in same file
  • Loading branch information
yakryder committed Oct 9, 2019
commit 7bb112fb4d2d129d3f01ab579f9c1bf01014d928
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