From ba02e3f1c9ec5f8c8f58438dc0753f5f0336c20a Mon Sep 17 00:00:00 2001 From: MareStare Date: Mon, 17 Mar 2025 23:21:54 +0000 Subject: [PATCH] Skip empty parts --- .../utils/__tests__/suggestion-model.spec.ts | 26 +++++++++++++++++++ assets/js/utils/suggestions-model.ts | 4 +++ 2 files changed, 30 insertions(+) diff --git a/assets/js/utils/__tests__/suggestion-model.spec.ts b/assets/js/utils/__tests__/suggestion-model.spec.ts index b02858cf..5c248e90 100644 --- a/assets/js/utils/__tests__/suggestion-model.spec.ts +++ b/assets/js/utils/__tests__/suggestion-model.spec.ts @@ -34,4 +34,30 @@ describe('prefixMatchParts', () => { ] `); }); + + it(`should ignore case when matching`, () => { + expect(prefixMatchParts('FOObar', 'foo')).toMatchInlineSnapshot(` + [ + { + "matched": "FOO", + }, + "bar", + ] + `); + }); + + it(`should skip empty parts`, () => { + expect(prefixMatchParts('foo', 'foo')).toMatchInlineSnapshot(` + [ + { + "matched": "foo", + }, + ] + `); + expect(prefixMatchParts('foo', 'bar')).toMatchInlineSnapshot(` + [ + "foo", + ] + `); + }); }); diff --git a/assets/js/utils/suggestions-model.ts b/assets/js/utils/suggestions-model.ts index cac4b4dd..4df9c1b8 100644 --- a/assets/js/utils/suggestions-model.ts +++ b/assets/js/utils/suggestions-model.ts @@ -51,6 +51,10 @@ export type TagSuggestion = CanonicalTagSuggestion | AliasTagSuggestion; * contains the `prefix` after the namespace separator. */ export function prefixMatchParts(target: string, prefix: string): MatchPart[] { + return prefixMatchPartsImpl(target, prefix).filter(part => typeof part !== 'string' || part.length > 0); +} + +function prefixMatchPartsImpl(target: string, prefix: string): MatchPart[] { const targetLower = target.toLowerCase(); const prefixLower = prefix.toLowerCase();