From 918b32c80ddd4f25c8fecbd69b4fdcc3919a066e Mon Sep 17 00:00:00 2001 From: Alex Hernandez Date: Mon, 2 Mar 2026 18:38:23 +1000 Subject: [PATCH] :bug: prevent overlapping feedback --- src/renderer/utils/annotationParser.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/renderer/utils/annotationParser.ts b/src/renderer/utils/annotationParser.ts index 36c1bc7..8e0c745 100644 --- a/src/renderer/utils/annotationParser.ts +++ b/src/renderer/utils/annotationParser.ts @@ -61,7 +61,19 @@ export function parseAnnotationsFromAIResponse( }) } - return annotations + return deduplicateOverlapping(annotations) +} + +function deduplicateOverlapping(annotations: TextAnnotation[]): TextAnnotation[] { + // Process largest spans first so the bigger annotation always wins over any + // overlapping smaller one (e.g. a full sentence beats a sub-phrase within it). + const sorted = [...annotations].sort((a, b) => (b.to - b.from) - (a.to - a.from)) + const kept: TextAnnotation[] = [] + for (const ann of sorted) { + const overlaps = kept.some(k => ann.from < k.to && ann.to > k.from) + if (!overlaps) kept.push(ann) + } + return kept } function classifyType(contextBefore: string): AnnotationType {