mirror of
https://github.com/peritus/obsidian-interactive-ratings.git
synced 2026-07-22 05:43:17 +00:00
Extract filterOverlappingMatches function from ratingViewPlugin.ts
This commit is contained in:
parent
7c9ac9d5cd
commit
785efc88ed
1 changed files with 22 additions and 0 deletions
|
|
@ -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;
|
||||
}
|
||||
Loading…
Reference in a new issue