MCPcopy Index your code
hub / github.com/tinymce/tinymce / removeRngStyle

Function removeRngStyle

modules/tinymce/src/core/main/ts/fmt/RemoveFormat.ts:537–610  ·  view source on GitHub ↗
(rng: Range)

Source from the content-addressed store, hash-verified

535 };
536
537 const removeRngStyle = (rng: Range) => {
538 let startContainer: Node;
539 let endContainer: Node;
540
541 let expandedRng = ExpandRange.expandRng(dom, rng, formatList, { includeTrailingSpace: rng.collapsed });
542
543 if (format.split) {
544 // Split text nodes
545 expandedRng = SplitRange.split(expandedRng);
546
547 startContainer = getContainer(ed, expandedRng, true);
548 endContainer = getContainer(ed, expandedRng);
549
550 if (startContainer !== endContainer) {
551 // WebKit will render the table incorrectly if we wrap a TH or TD in a SPAN
552 // so let's see if we can use the first/last child instead
553 // This will happen if you triple click a table cell and use remove formatting
554 startContainer = normalizeTableSelection(startContainer, true);
555 endContainer = normalizeTableSelection(endContainer, false);
556
557 // Wrap and split if nested
558 if (isChildOfInlineParent(dom, startContainer, endContainer)) {
559 const marker = Optional.from(startContainer.firstChild).getOr(startContainer);
560 splitToFormatRoot(wrapWithSiblings(dom, marker, true, 'span', { 'id': '_start', 'data-mce-type': 'bookmark' }));
561 unwrap(true);
562 return;
563 }
564
565 // Wrap and split if nested
566 if (isChildOfInlineParent(dom, endContainer, startContainer)) {
567 const marker = Optional.from(endContainer.lastChild).getOr(endContainer);
568 splitToFormatRoot(wrapWithSiblings(dom, marker, false, 'span', { 'id': '_end', 'data-mce-type': 'bookmark' }));
569 unwrap(false);
570 return;
571 }
572
573 // Wrap start/end nodes in span element since these might be cloned/moved
574 startContainer = wrap(dom, startContainer, 'span', { 'id': '_start', 'data-mce-type': 'bookmark' });
575 endContainer = wrap(dom, endContainer, 'span', { 'id': '_end', 'data-mce-type': 'bookmark' });
576
577 // Split start/end and anything in between
578 const newRng = dom.createRng();
579 newRng.setStartAfter(startContainer);
580 newRng.setEndBefore(endContainer);
581 RangeWalk.walk(dom, newRng, (nodes) => {
582 Arr.each(nodes, (n) => {
583 if (!Bookmarks.isBookmarkNode(n) && !Bookmarks.isBookmarkNode(n.parentNode)) {
584 splitToFormatRoot(n);
585 }
586 });
587 });
588 splitToFormatRoot(startContainer);
589 splitToFormatRoot(endContainer);
590
591 // Unwrap start/end to get real elements again
592 // Note that the return value should always be a node since it's wrapped above
593 startContainer = unwrap(true) as Node;
594 endContainer = unwrap() as Node;

Callers 1

removeFormatInternalFunction · 0.85

Calls 11

getContainerFunction · 0.85
normalizeTableSelectionFunction · 0.85
isChildOfInlineParentFunction · 0.85
splitToFormatRootFunction · 0.85
wrapWithSiblingsFunction · 0.85
getOrMethod · 0.80
fromMethod · 0.80
walkMethod · 0.80
eachMethod · 0.80
unwrapFunction · 0.70
wrapFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…