Skip to content

Commit

Permalink
Merge branch 'highlight-speedups' of https://github.com/peitschie/rangy
Browse files Browse the repository at this point in the history
… into peitschie-highlight-speedups
  • Loading branch information
Tim committed Oct 23, 2014
2 parents 2d2a87c + 0e8a71c commit 6cc160e
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/modules/rangy-classapplier.js
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,24 @@ rangy.createModule("ClassApplier", ["WrappedSelection"], function(api, module) {
ancestorWithClass = splitNodeAt(ancestorWithClass, range.startContainer, range.startOffset, positionsToPreserve);
}
}

log.info("isRemovable", this.isRemovable(ancestorWithClass), dom.inspectNode(ancestorWithClass), "'" + ancestorWithClass.innerHTML + "'", "'" + ancestorWithClass.parentNode.innerHTML + "'");
if (this.isRemovable(ancestorWithClass)) {
replaceWithOwnChildrenPreservingPositions(ancestorWithClass, positionsToPreserve);
} else {
removeClass(ancestorWithClass, this.className);
}
},

splitAncestorWithClass: function(container, offset, positionsToPreserve) {
var ancestorWithClass = this.getSelfOrAncestorWithClass(container);
if (ancestorWithClass) {
log.info("splitAncestorWithClass", dom.inspectNode(ancestorWithClass), dom.inspectNode(container), offset);
splitNodeAt(ancestorWithClass, container, offset, positionsToPreserve);
}
},

undoToAncestor: function(ancestorWithClass, positionsToPreserve) {
log.info("isRemovable", this.isRemovable(ancestorWithClass), dom.inspectNode(ancestorWithClass), "'" + ancestorWithClass.innerHTML + "'", "'" + ancestorWithClass.parentNode.innerHTML + "'");
if (this.isRemovable(ancestorWithClass)) {
replaceWithOwnChildrenPreservingPositions(ancestorWithClass, positionsToPreserve);
Expand Down Expand Up @@ -878,16 +896,17 @@ rangy.createModule("ClassApplier", ["WrappedSelection"], function(api, module) {
var lastTextNode = textNodes[textNodes.length - 1];

if (textNodes.length) {
this.splitAncestorWithClass(range.endContainer, range.endOffset, positionsToPreserve);
this.splitAncestorWithClass(range.startContainer, range.startOffset, positionsToPreserve);
for (var i = 0, len = textNodes.length; i < len; ++i) {
textNode = textNodes[i];
ancestorWithClass = this.getSelfOrAncestorWithClass(textNode);
if (ancestorWithClass && this.isModifiable(textNode)) {
this.undoToTextNode(textNode, range, ancestorWithClass, positionsToPreserve);
this.undoToAncestor(ancestorWithClass, positionsToPreserve);
}

// Ensure the range is still valid
range.setStartAndEnd(textNodes[0], 0, lastTextNode, lastTextNode.length);
}
// Ensure the range is still valid
range.setStartAndEnd(textNodes[0], 0, lastTextNode, lastTextNode.length);

log.info("Undo set range to '" + textNodes[0].data + "', '" + textNode.data + "'");

Expand Down

0 comments on commit 6cc160e

Please sign in to comment.