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

Function wrapAndSplit

modules/tinymce/src/core/main/ts/fmt/RemoveFormat.ts:386–447  ·  view source on GitHub ↗
(
  editor: Editor,
  formatList: Format[],
  formatRoot: Node | undefined,
  container: Node,
  target: Node,
  split: boolean,
  format: Format,
  vars?: FormatVars
)

Source from the content-addressed store, hash-verified

384 );
385
386const wrapAndSplit = (
387 editor: Editor,
388 formatList: Format[],
389 formatRoot: Node | undefined,
390 container: Node,
391 target: Node,
392 split: boolean,
393 format: Format,
394 vars?: FormatVars
395) => {
396 let lastClone: Node | undefined;
397 let firstClone: Node | undefined;
398 const dom = editor.dom;
399
400 // Format root found then clone formats and split it
401 if (formatRoot) {
402 const formatRootParent = formatRoot.parentNode;
403
404 for (let parent = container.parentNode; parent && parent !== formatRootParent; parent = parent.parentNode) {
405 let clone: Node | null = dom.clone(parent, false);
406
407 for (let i = 0; i < formatList.length; i++) {
408 clone = removeNodeFormatFromClone(editor, formatList[i], vars, clone);
409 if (clone === null) {
410 break;
411 }
412 }
413
414 // Build wrapper node
415 if (clone) {
416 if (lastClone) {
417 clone.appendChild(lastClone);
418 }
419
420 if (!firstClone) {
421 firstClone = clone;
422 }
423
424 lastClone = clone;
425 }
426 }
427
428 // Never split block elements if the format is mixed
429 if (split && (!format.mixed || !dom.isBlock(formatRoot))) {
430 container = dom.split(formatRoot, container) ?? container;
431 }
432
433 // Wrap container in cloned formats
434 if (lastClone && firstClone) {
435 target.parentNode?.insertBefore(lastClone, target);
436 firstClone.appendChild(target);
437
438 // After splitting the nodes may match with other siblings so we need to attempt to merge them
439 // Note: We can't use MergeFormats, as that'd create a circular dependency
440 if (FormatUtils.isInlineFormat(format)) {
441 mergeSiblings(editor, format, vars, lastClone);
442 }
443 }

Callers 1

splitToFormatRootFunction · 0.85

Calls 3

mergeSiblingsFunction · 0.90
cloneMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…