From 785efc88ed2f7cbac414d9f32bb26c4be4ad031e Mon Sep 17 00:00:00 2001 From: Filip Noetzel Date: Tue, 10 Jun 2025 11:52:24 +0200 Subject: [PATCH] Extract filterOverlappingMatches function from ratingViewPlugin.ts --- .../filterOverlappingMatches.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/editor-extension/ratingViewPlugin/filterOverlappingMatches.ts diff --git a/src/editor-extension/ratingViewPlugin/filterOverlappingMatches.ts b/src/editor-extension/ratingViewPlugin/filterOverlappingMatches.ts new file mode 100644 index 0000000..0848848 --- /dev/null +++ b/src/editor-extension/ratingViewPlugin/filterOverlappingMatches.ts @@ -0,0 +1,22 @@ +import { RatingMatch } from '../RatingMatch'; + +/** + * Filter overlapping matches, keeping the first one in each overlapping group + */ +export function filterOverlappingMatches(matches: RatingMatch[]): RatingMatch[] { + // Sort matches by start position (required by RangeSetBuilder) + const sortedMatches = [...matches].sort((a, b) => a.start - b.start); + + // Remove overlapping matches (keep the first one) + const filteredMatches: RatingMatch[] = []; + let lastEnd = -1; + + for (const match of sortedMatches) { + if (match.start >= lastEnd) { + filteredMatches.push(match); + lastEnd = match.end; + } + } + + return filteredMatches; +} \ No newline at end of file