src/modules/rangy-classapplier.js
function(textNodes, range, positionsToPreserve, isUndo) {
            log.group("postApply " + range.toHtml());
            var firstNode = textNodes[0], lastNode = textNodes[textNodes.length - 1];
            var merges = [], currentMerge;
            var rangeStartNode = firstNode, rangeEndNode = lastNode;
            var rangeStartOffset = 0, rangeEndOffset = lastNode.length;
            var precedingTextNode;

            // Check for every required merge and create a Merge object for each
            forEach(textNodes, function(textNode) {
                precedingTextNode = getPreviousMergeableTextNode(textNode, !isUndo);
                log.debug("Checking for merge. text node: " + textNode.data + ", parent: " + dom.inspectNode(textNode.parentNode) + ", preceding: " + dom.inspectNode(precedingTextNode));
                if (precedingTextNode) {
                    if (!currentMerge) {
                        currentMerge = new Merge(precedingTextNode);
                        merges.push(currentMerge);
                    }
                    currentMerge.textNodes.push(textNode);
                    if (textNode === firstNode) {
                        rangeStartNode = currentMerge.textNodes[0];
                        rangeStartOffset = rangeStartNode.length;
                    }
                    if (textNode === lastNode) {
                        rangeEndNode = currentMerge.textNodes[0];
                        rangeEndOffset = currentMerge.getLength();
                    }
                } else {
                    currentMerge = null;
                }
            });

            // Test whether the first node after the range needs merging
            var nextTextNode = getNextMergeableTextNode(lastNode, !isUndo);

            if (nextTextNode) {
                if (!currentMerge) {
                    currentMerge = new Merge(lastNode);
                    merges.push(currentMerge);
                }
                currentMerge.textNodes.push(nextTextNode);
            }

            // Apply the merges
            if (merges.length) {
                log.info("Merging. Merges:", merges);
                for (var i = 0, len = merges.length; i < len; ++i) {
                    merges[i].doMerge(positionsToPreserve);
                }
                log.info(rangeStartNode.nodeValue, rangeStartOffset, rangeEndNode.nodeValue, rangeEndOffset);

                // Set the range boundaries
                range.setStartAndEnd(rangeStartNode, rangeStartOffset, rangeEndNode, rangeEndOffset);
                log.info("Range after merge: " + range.inspect());
            }
            log.groupEnd();
        }
function(textNodes, range, positionsToPreserve, isUndo) {
            log.group("postApply " + range.toHtml());
            var firstNode = textNodes[0], lastNode = textNodes[textNodes.length - 1];
            var merges = [], currentMerge;
            var rangeStartNode = firstNode, rangeEndNode = lastNode;
            var rangeStartOffset = 0, rangeEndOffset = lastNode.length;
            var precedingTextNode;

            // Check for every required merge and create a Merge object for each
            forEach(textNodes, function(textNode) {
                precedingTextNode = getPreviousMergeableTextNode(textNode, !isUndo);
                log.debug("Checking for merge. text node: " + textNode.data + ", parent: " + dom.inspectNode(textNode.parentNode) + ", preceding: " + dom.inspectNode(precedingTextNode));
                if (precedingTextNode) {
                    if (!currentMerge) {
                        currentMerge = new Merge(precedingTextNode);
                        merges.push(currentMerge);
                    }
                    currentMerge.textNodes.push(textNode);
                    if (textNode === firstNode) {
                        rangeStartNode = currentMerge.textNodes[0];
                        rangeStartOffset = rangeStartNode.length;
                    }
                    if (textNode === lastNode) {
                        rangeEndNode = currentMerge.textNodes[0];
                        rangeEndOffset = currentMerge.getLength();
                    }
                } else {
                    currentMerge = null;
                }
            });

            // Test whether the first node after the range needs merging
            var nextTextNode = getNextMergeableTextNode(lastNode, !isUndo);

            if (nextTextNode) {
                if (!currentMerge) {
                    currentMerge = new Merge(lastNode);
                    merges.push(currentMerge);
                }
                currentMerge.textNodes.push(nextTextNode);
            }

            // Apply the merges
            if (merges.length) {
                log.info("Merging. Merges:", merges);
                for (var i = 0, len = merges.length; i < len; ++i) {
                    merges[i].doMerge(positionsToPreserve);
                }
                log.info(rangeStartNode.nodeValue, rangeStartOffset, rangeEndNode.nodeValue, rangeEndOffset);

                // Set the range boundaries
                range.setStartAndEnd(rangeStartNode, rangeStartOffset, rangeEndNode, rangeEndOffset);
                log.info("Range after merge: " + range.inspect());
            }
            log.groupEnd();
        }
function ( textNodes , range , positionsToPreserve , isUndo ) { log . group ( "postApply " + range . toHtml ( ) ) ; var firstNode = textNodes [ 0 ] , lastNode = textNodes [ textNodes . length - 1 ] ; var merges = [ ] , currentMerge ; var rangeStartNode = firstNode , rangeEndNode = lastNode ; var rangeStartOffset = 0 , rangeEndOffset = lastNode . length ; var precedingTextNode ; // Check for every required merge and create a Merge object for each forEach ( textNodes , function ( textNode ) { precedingTextNode = getPreviousMergeableTextNode ( textNode , ! isUndo ) ; log . debug ( "Checking for merge. text node: " + textNode . data + ", parent: " + dom . inspectNode ( textNode . parentNode ) + ", preceding: " + dom . inspectNode ( precedingTextNode ) ) ; if ( precedingTextNode ) { if ( ! currentMerge ) { currentMerge = new Merge ( precedingTextNode ) ; merges . push ( currentMerge ) ; } currentMerge . textNodes . push ( textNode ) ; if ( textNode === firstNode ) { rangeStartNode = currentMerge . textNodes [ 0 ] ; rangeStartOffset = rangeStartNode . length ; } if ( textNode === lastNode ) { rangeEndNode = currentMerge . textNodes [ 0 ] ; rangeEndOffset = currentMerge . getLength ( ) ; } } else { currentMerge = null ; } } ) ; // Test whether the first node after the range needs merging var nextTextNode = getNextMergeableTextNode ( lastNode , ! isUndo ) ; if ( nextTextNode ) { if ( ! currentMerge ) { currentMerge = new Merge ( lastNode ) ; merges . push ( currentMerge ) ; } currentMerge . textNodes . push ( nextTextNode ) ; } // Apply the merges if ( merges . length ) { log . info ( "Merging. Merges:" , merges ) ; for ( var i = 0 , len = merges . length ; i < len ; ++ i ) { merges [ i ] . doMerge ( positionsToPreserve ) ; } log . info ( rangeStartNode . nodeValue , rangeStartOffset , rangeEndNode . nodeValue , rangeEndOffset ) ; // Set the range boundaries range . setStartAndEnd ( rangeStartNode , rangeStartOffset , rangeEndNode , rangeEndOffset ) ; log . info ( "Range after merge: " + range . inspect ( ) ) ; } log . groupEnd ( ) ; }
Normalizes nodes after applying a class to a Range.
Normalizes nodes after applying a class to a Range .