* CodeMirror 更新回调
(update: ViewUpdate)
| 1522 | * CodeMirror 更新回调 |
| 1523 | */ |
| 1524 | private onCMUpdate(update: ViewUpdate): void { |
| 1525 | if (this.updating) return; |
| 1526 | |
| 1527 | if (update.docChanged) { |
| 1528 | const pos = this.getPos(); |
| 1529 | if (pos === undefined) return; |
| 1530 | |
| 1531 | const newText = update.state.doc.toString(); |
| 1532 | |
| 1533 | // 更新 ProseMirror 文档 |
| 1534 | const tr = this.view.state.tr; |
| 1535 | const start = pos + 1; |
| 1536 | const end = pos + 1 + this.node.content.size; |
| 1537 | |
| 1538 | tr.replaceWith(start, end, newText ? this.view.state.schema.text(newText) : []); |
| 1539 | |
| 1540 | this.view.dispatch(tr); |
| 1541 | |
| 1542 | // 更新 Mermaid 预览 |
| 1543 | if (this.node.attrs.language === "mermaid") { |
| 1544 | this.createMermaidPreview(newText); |
| 1545 | } |
| 1546 | } |
| 1547 | } |
| 1548 | |
| 1549 | /** |
| 1550 | * 转发选区到 ProseMirror |
no test coverage detected