mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-09-24 16:02:55 +08:00
Merge pull request #10287 from Kilo-Org/eight-timbale
fix(agent-manager): stabilize markdown review capture
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"kilo-code": patch
|
||||
---
|
||||
|
||||
Keep inline review voice capture stable in rendered Markdown diffs.
|
||||
@@ -0,0 +1,20 @@
|
||||
import { describe, expect, it } from "bun:test"
|
||||
import { isAnnotationMutation } from "../../webview-ui/agent-manager/MarkdownAnnotationLayer"
|
||||
|
||||
function mutation(target: Node): Pick<MutationRecord, "target"> {
|
||||
return { target }
|
||||
}
|
||||
|
||||
describe("isAnnotationMutation", () => {
|
||||
it("matches nested annotation DOM mutations", () => {
|
||||
const target = { closest: () => ({}) } as unknown as Node
|
||||
expect(isAnnotationMutation(mutation(target))).toBe(true)
|
||||
})
|
||||
|
||||
it("keeps external Markdown DOM mutations observable", () => {
|
||||
const markdown = { closest: () => null } as unknown as Node
|
||||
const plain = {} as Node
|
||||
expect(isAnnotationMutation(mutation(markdown))).toBe(false)
|
||||
expect(isAnnotationMutation(mutation(plain))).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -88,11 +88,19 @@ function matches(annotation: DiffLineAnnotation<AnnotationMeta>, anchor: Anchor,
|
||||
return true
|
||||
}
|
||||
|
||||
const selector = ".am-markdown-inline-annotations, .am-markdown-list-annotation, .am-markdown-table-annotation"
|
||||
|
||||
// Keep host insertion observable, only nested annotation UI updates are safe to ignore.
|
||||
export function isAnnotationMutation(mutation: Pick<MutationRecord, "target">): boolean {
|
||||
const target = mutation.target
|
||||
if (!("closest" in target)) return false
|
||||
if (typeof target.closest !== "function") return false
|
||||
return target.closest(selector) !== null
|
||||
}
|
||||
|
||||
function removeInserted(root: HTMLElement, layer: HTMLElement): void {
|
||||
layer.replaceChildren()
|
||||
root
|
||||
.querySelectorAll(".am-markdown-inline-annotations, .am-markdown-list-annotation, .am-markdown-table-annotation")
|
||||
.forEach((node) => node.remove())
|
||||
root.querySelectorAll(selector).forEach((node) => node.remove())
|
||||
}
|
||||
|
||||
function insertHost(anchor: Anchor, host: HTMLElement): void {
|
||||
@@ -206,7 +214,10 @@ export const MarkdownAnnotationLayer: Component<MarkdownAnnotationLayerProps> =
|
||||
const root = props.root()
|
||||
if (!root) return
|
||||
observer?.disconnect()
|
||||
observer = new MutationObserver(schedule)
|
||||
observer = new MutationObserver((mutations) => {
|
||||
if (mutations.every(isAnnotationMutation)) return
|
||||
schedule()
|
||||
})
|
||||
observer.observe(root, { childList: true, subtree: true })
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user