( editor: Editor, formatList: Format[], formatRoot: Node | undefined, container: Node, target: Node, split: boolean, format: Format, vars?: FormatVars )
| 384 | ); |
| 385 | |
| 386 | const 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 | } |
no test coverage detected
searching dependent graphs…