From d683a54da0e1f43cb9ef9bdb54ba49551839a640 Mon Sep 17 00:00:00 2001 From: Charlie Kolb Date: Mon, 12 May 2025 17:06:19 +0200 Subject: [PATCH] fix(editor): Make `AI Agent` appear before `Magento 2` when typing `agent` (#15302) --- packages/@n8n/utils/src/search/sublimeSearch.test.ts | 9 +++++++-- packages/@n8n/utils/src/search/sublimeSearch.ts | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/@n8n/utils/src/search/sublimeSearch.test.ts b/packages/@n8n/utils/src/search/sublimeSearch.test.ts index 6fee13d1aa0..f725e26e7ee 100644 --- a/packages/@n8n/utils/src/search/sublimeSearch.test.ts +++ b/packages/@n8n/utils/src/search/sublimeSearch.test.ts @@ -2,8 +2,13 @@ import topLevel from './snapshots/toplevel.snapshot.json'; import { sublimeSearch } from './sublimeSearch'; describe('sublimeSearch', () => { - describe('search finds at least one match', () => { - const testCases: Array<[string, string[]]> = [['agent', ['Magento 2', 'AI Agent']]]; + describe('search finds specific matches first', () => { + // Note that this only tests the order of the specified matches + // Further results may appear after the listed ones + const testCases: Array<[string, string[]]> = [ + ['set', ['Edit Fields (Set)']], + ['agent', ['AI Agent', 'Magento 2']], + ]; test.each(testCases)( 'should return at least "$expectedOrder" for filter "$filter"', diff --git a/packages/@n8n/utils/src/search/sublimeSearch.ts b/packages/@n8n/utils/src/search/sublimeSearch.ts index 539541a7838..5746424bec5 100644 --- a/packages/@n8n/utils/src/search/sublimeSearch.ts +++ b/packages/@n8n/utils/src/search/sublimeSearch.ts @@ -4,7 +4,7 @@ */ const SEQUENTIAL_BONUS = 60; // bonus for adjacent matches -const SEPARATOR_BONUS = 30; // bonus if match occurs after a separator +const SEPARATOR_BONUS = 38; // bonus if match occurs after a separator const CAMEL_BONUS = 30; // bonus if match is uppercase and prev is lower const FIRST_LETTER_BONUS = 15; // bonus if the first letter is matched