From 7b562aea508e8b388e3ef4e65d73557a88ba998a Mon Sep 17 00:00:00 2001 From: Darin Kelkhoff Date: Fri, 17 May 2024 17:11:35 -0500 Subject: [PATCH] Slightly better sort for multi-word search terms --- src/CommandMenu.tsx | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/CommandMenu.tsx b/src/CommandMenu.tsx index 67fde61..b59e95e 100644 --- a/src/CommandMenu.tsx +++ b/src/CommandMenu.tsx @@ -189,16 +189,20 @@ const CommandMenu = ({metaData}: Props) => return B_FIRST; } - aStartsWith = labelA.toLowerCase().startsWith(searchString.toLowerCase()); - bStartsWith = labelB.toLowerCase().startsWith(searchString.toLowerCase()); + const indexOfSpace = searchString.indexOf(" "); + if (indexOfSpace > 0) + { + aStartsWith = labelA.toLowerCase().startsWith(searchString.substring(0, indexOfSpace).toLowerCase()); + bStartsWith = labelB.toLowerCase().startsWith(searchString.substring(0, indexOfSpace).toLowerCase()); - if (aStartsWith && !bStartsWith) - { - return A_FIRST; - } - else if (bStartsWith && !aStartsWith) - { - return B_FIRST; + if (aStartsWith && !bStartsWith) + { + return A_FIRST; + } + else if (bStartsWith && !aStartsWith) + { + return B_FIRST; + } } } @@ -439,7 +443,7 @@ const CommandMenu = ({metaData}: Props) => { - doFilter(value, search)}> + doFilter(value, search)}>