if (blocks[i].comparePoint(clonedSelectionRange.endContainer, clonedSelectionRange.endOffset) === 0) {
clonedSelectionRange.setEnd(blocks[i].endContainer, blocks[i].endOffset);
}
}
}
return clonedSelectionRange;
}
function toggleSurroundRangeSet(range, options) {
var blockOptions = new $.Arte.ElementApplierOptions(options);
var expandedRanges = expandRange(range, options.topEditableParent);
blockOptions.originalRange = expandedRanges;
var splitRanges = expandedRanges.splitByBlock();
var surroundState = isBlockSetSurrounded(splitRanges, blockOptions);
blockOptions.blockSurroundState = surroundState;
if (surroundState.state() === surroundState.UnSurrounded ||
surroundState.state() === surroundState.Mixed) {
surroundRangeSet(splitRanges, blockOptions);
} else if (surroundState.state() === surroundState.Surrounded) {
unSurroundRangeSet(splitRanges, blockOptions);
}
}
function toggleSurroundSelectionSet(options, topEditableParent) {
var blockOptions = new $.Arte.ElementApplierOptions(options, topEditableParent);
var selection = rangy.getSelection();
var range = selection.getRangeAt(0);
if (range) {
toggleSurroundRangeSet(range, blockOptions);
}
}
function toggleSurroundRange(range, options) {
if (range.isCollapsed) {
return;
}
var blockOptions = new $.Arte.ElementApplierOptions(options);
var expandedRange = expandRange(range, options.topEditableParent);
var splitRanges = expandedRange.splitByBlock();
var surroundState = areRangesBlockSurrounded(splitRanges, blockOptions);
var nodesByRange = getTopNodesFromRanges(splitRanges);