Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ describe('isPartHighlighted', () => {
).toEqual(true);
});

test('does not inherit sibling state when siblings disagree', () => {
// The separator (index 1) sits between a highlighted ("Amazon") and a
// non-highlighted ("Fire") part. Since the siblings disagree, the separator
// must keep its own `isHighlighted` value rather than being treated as
// highlighted-from-siblings.
expect(
isPartHighlighted(
[
{ isHighlighted: true, value: 'Amazon' },
{ isHighlighted: false, value: ' - ' },
{ isHighlighted: false, value: 'Fire' },
],
1
)
).toEqual(false);
});

test('returns the isHighlighted value with both siblings', () => {
expect(
isPartHighlighted(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ function unescape(value: string): string {

export function isPartHighlighted(parts: ParsedAttribute[], i: number) {
const current = parts[i];
const isNextHighlighted = parts[i + 1]?.isHighlighted || true;
const isPreviousHighlighted = parts[i - 1]?.isHighlighted || true;
const isNextHighlighted = parts[i + 1]?.isHighlighted ?? true;
const isPreviousHighlighted = parts[i - 1]?.isHighlighted ?? true;

if (
!hasLetterOrNumber.test(unescape(current.value)) &&
Expand Down