From 9447071d64938ea337c0a52db03438241071474f Mon Sep 17 00:00:00 2001 From: Chris Kruining Date: Tue, 4 Feb 2025 15:27:45 +1100 Subject: [PATCH] fix the command highlighting code --- src/features/command/palette.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/features/command/palette.tsx b/src/features/command/palette.tsx index 084eeb3..6959114 100644 --- a/src/features/command/palette.tsx +++ b/src/features/command/palette.tsx @@ -56,10 +56,16 @@ export const CommandPalette: Component<{ api?: (api: CommandPaletteApi) => any, return setOpen(false)}> t(item.label) as string} context={setSearch} onSubmit={onSubmit}>{ - (item, ctx) => {(part, index) => <> - {ctx.filter()} - {part} - } + (item, ctx) => { + const label = t(item.label) as string; + const filter = ctx.filter().toLowerCase(); + const length = filter.length; + const indices = [0, ...Array.from(label.matchAll(new RegExp(filter, 'gi')).flatMap(({ index }) => [index, index + length]))]; + + return label.slice(current, indices[i + 1]))}>{ + (part) => {part} + }; + } } ; };