MCPcopy Create free account
hub / github.com/anomalyco/opencode / updateBlock

Function updateBlock

packages/session-ui/src/components/markdown.tsx:550–594  ·  view source on GitHub ↗
(container: HTMLDivElement, index: number, block: RenderedBlock, labels: CopyLabels)

Source from the content-addressed store, hash-verified

548}
549
550function updateBlock(container: HTMLDivElement, index: number, block: RenderedBlock, labels: CopyLabels) {
551 const current = container.children[index]
552 if (block.mode === "code") {
553 updateCodeBlock(container, current, block, labels)
554 return
555 }
556 if (
557 current instanceof HTMLDivElement &&
558 current.dataset.markdownKey === block.key &&
559 current.dataset.markdownHash === block.hash
560 )
561 return
562
563 const next = document.createElement("div")
564 next.dataset.markdownBlock = ""
565 next.dataset.markdownKey = block.key
566 next.dataset.markdownHash = block.hash
567 next.style.display = "contents"
568 next.innerHTML = block.html
569 decorate(next, labels)
570
571 if (!(current instanceof HTMLDivElement)) {
572 container.appendChild(next)
573 return
574 }
575
576 morphdom(current, next, {
577 onBeforeElUpdated: (fromEl, toEl) => {
578 if (
579 fromEl instanceof HTMLElement &&
580 toEl instanceof HTMLElement &&
581 fromEl.getAttribute("data-slot") === "markdown-copy-button" &&
582 toEl.getAttribute("data-slot") === "markdown-copy-button"
583 ) {
584 return false
585 }
586 if (fromEl.isEqualNode(toEl)) return false
587 return true
588 },
589 onBeforeNodeDiscarded: (node) => {
590 if (node instanceof Element) disposeCopyButtons(node)
591 return true
592 },
593 })
594}
595
596function updateCodeBlock(
597 container: HTMLDivElement,

Callers 1

MarkdownFunction · 0.85

Calls 3

updateCodeBlockFunction · 0.85
decorateFunction · 0.85
disposeCopyButtonsFunction · 0.85

Tested by

no test coverage detected