MCPcopy Create free account
hub / github.com/Auto-Plugin/milkup / deleteCodeBlock

Method deleteCodeBlock

src/core/nodeviews/code-block.ts:1653–1673  ·  view source on GitHub ↗

* 删除代码块

()

Source from the content-addressed store, hash-verified

1651 * 删除代码块
1652 */
1653 private deleteCodeBlock(): void {
1654 const pos = this.getPos();
1655 if (pos === undefined) return;
1656
1657 const { state } = this.view;
1658 const nodeEnd = pos + this.node.nodeSize;
1659
1660 const tr = state.tr.delete(pos, nodeEnd);
1661
1662 if (tr.doc.content.size === 0) {
1663 const paragraph = state.schema.nodes.paragraph.create();
1664 tr.insert(0, paragraph);
1665 tr.setSelection(TextSelection.create(tr.doc, 1));
1666 } else {
1667 const $pos = tr.doc.resolve(Math.min(pos, tr.doc.content.size));
1668 tr.setSelection(Selection.near($pos, -1));
1669 }
1670
1671 this.view.dispatch(tr);
1672 this.view.focus();
1673 }
1674
1675 /**
1676 * 更新节点

Callers 2

constructorMethod · 0.95
showContextMenuMethod · 0.95

Calls 2

focusMethod · 0.80
setSelectionMethod · 0.45

Tested by

no test coverage detected