(editor, name, vars, similar)
| 13534 | } |
| 13535 | }; |
| 13536 | const removeCaretFormat = (editor, name, vars, similar) => { |
| 13537 | const dom = editor.dom; |
| 13538 | const selection = editor.selection; |
| 13539 | let hasContentAfter = false; |
| 13540 | const formatList = editor.formatter.get(name); |
| 13541 | if (!formatList) { |
| 13542 | return; |
| 13543 | } |
| 13544 | const rng = selection.getRng(); |
| 13545 | const container = rng.startContainer; |
| 13546 | const offset = rng.startOffset; |
| 13547 | let node = container; |
| 13548 | if (isText$a(container)) { |
| 13549 | if (offset !== container.data.length) { |
| 13550 | hasContentAfter = true; |
| 13551 | } |
| 13552 | node = node.parentNode; |
| 13553 | } |
| 13554 | const parents = []; |
| 13555 | let formatNode; |
| 13556 | while (node) { |
| 13557 | if (matchNode(editor, node, name, vars, similar)) { |
| 13558 | formatNode = node; |
| 13559 | break; |
| 13560 | } |
| 13561 | if (node.nextSibling) { |
| 13562 | hasContentAfter = true; |
| 13563 | } |
| 13564 | parents.push(node); |
| 13565 | node = node.parentNode; |
| 13566 | } |
| 13567 | if (!formatNode) { |
| 13568 | return; |
| 13569 | } |
| 13570 | if (hasContentAfter) { |
| 13571 | const bookmark = selection.getBookmark(); |
| 13572 | rng.collapse(true); |
| 13573 | let expandedRng = expandRng(dom, rng, formatList, true); |
| 13574 | expandedRng = split(expandedRng); |
| 13575 | editor.formatter.remove(name, vars, expandedRng, similar); |
| 13576 | selection.moveToBookmark(bookmark); |
| 13577 | } else { |
| 13578 | const caretContainer = getParentCaretContainer(editor.getBody(), formatNode); |
| 13579 | const parentsAfter = isNonNullable(caretContainer) ? dom.getParents(formatNode.parentNode, always, caretContainer) : []; |
| 13580 | const newCaretContainer = createCaretContainer(false).dom; |
| 13581 | insertCaretContainerNode(editor, newCaretContainer, caretContainer !== null && caretContainer !== void 0 ? caretContainer : formatNode); |
| 13582 | const cleanedFormatNode = cleanFormatNode(editor, newCaretContainer, formatNode, name, vars, similar); |
| 13583 | const caretTextNode = insertFormatNodesIntoCaretContainer([ |
| 13584 | ...parents, |
| 13585 | ...cleanedFormatNode.toArray(), |
| 13586 | ...parentsAfter |
| 13587 | ], newCaretContainer); |
| 13588 | if (caretContainer) { |
| 13589 | removeCaretContainerNode(editor, caretContainer, isNonNullable(caretContainer)); |
| 13590 | } |
| 13591 | selection.setCursorLocation(caretTextNode, 1); |
| 13592 | if (dom.isEmpty(formatNode)) { |
| 13593 | dom.remove(formatNode); |
no test coverage detected