Skip to content

Commit 255754f

Browse files
Better filtering of highlights
1 parent 7ce775f commit 255754f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

packages/cursorless-org-docs/src/docs/components/flattenHighlights.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ import type { BorderRadius, Highlight, Style } from "./types";
1010
export function flattenHighlights(highlights: Highlight[]): Highlight[] {
1111
const positions = getPositions(highlights);
1212
const results: Highlight[] = [];
13-
1413
for (let i = 0; i < positions.length - 1; i++) {
1514
const range = new Range(positions[i], positions[i + 1]);
1615

17-
const matchingHighlights = highlights.filter(({ range }) =>
18-
range.contains(range),
19-
);
16+
const matchingHighlights = range.isEmpty
17+
? highlights.filter((h) => range.contains(range))
18+
: highlights.filter((h) => {
19+
const intersection = h.range.intersection(range);
20+
return intersection && !intersection.isEmpty;
21+
});
2022

2123
// This sub could be between two scopes.
2224
if (matchingHighlights.length === 0) {

0 commit comments

Comments
 (0)