feat(search): show search result snippets with match highlighting (#219) #242

Merged
marcel merged 20 commits from feat/issue-219-search-snippets into main 2026-04-16 09:10:11 +02:00
Showing only changes of commit 89d2c47f8f - Show all commits

View File

@@ -92,4 +92,19 @@ describe('applyOffsets', () => {
{ text: 'Brief', highlight: true }
]);
});
it('clamps negative start to 0 and highlights from the beginning', () => {
// start = -2, length = 5 → effective range [-2, 3) → clamped to [0, 3)
expect(applyOffsets('Hello', [{ start: -2, length: 5 }])).toEqual([
{ text: 'Hel', highlight: true },
{ text: 'lo', highlight: false }
]);
});
it('ignores offset whose end is also negative', () => {
// start = -5, length = 2 → end = -3, completely before text
expect(applyOffsets('Hi', [{ start: -5, length: 2 }])).toEqual([
{ text: 'Hi', highlight: false }
]);
});
});