Scopes: Increase rank for recent scopes in command palette (#111805)
* Increase prio for recent scopes and bump match score for exact matches * Set scopes prio to 8
This commit is contained in:
@@ -16,12 +16,20 @@ export function getRecentScopesActions(): CommandPaletteAction[] {
|
||||
const recentScopes = scopesSelectorService.getRecentScopes();
|
||||
|
||||
return recentScopes.map((recentScope) => {
|
||||
const names = recentScope.map((scope) => scope.spec.title).join(', ');
|
||||
const keywords = recentScope
|
||||
.map((scope) => `${scope.spec.title} ${scope.metadata.name}`)
|
||||
.concat(names)
|
||||
.join(' ');
|
||||
return {
|
||||
id: recentScope.map((scope) => scope.spec.title).join(', '),
|
||||
name: recentScope.map((scope) => scope.spec.title).join(', '),
|
||||
section: t('command-palette.section.recent-scopes', 'Recent scopes'),
|
||||
// Only show the parent of the first scope for now
|
||||
id: names,
|
||||
name: names,
|
||||
section: {
|
||||
name: t('command-palette.section.recent-scopes', 'Recent scopes'),
|
||||
priority: RECENT_SCOPES_PRIORITY,
|
||||
},
|
||||
subtitle: recentScope[0]?.parentNode?.spec.title,
|
||||
keywords: keywords,
|
||||
priority: RECENT_SCOPES_PRIORITY,
|
||||
perform: () => {
|
||||
scopesSelectorService.changeScopes(recentScope.map((scope) => scope.metadata.name));
|
||||
|
||||
@@ -190,10 +190,18 @@ function useInternalMatches(filtered: ActionImpl[], search: string): Match[] {
|
||||
const matchingIndices = fuzzySearch(haystack, throttledSearch);
|
||||
|
||||
// Convert indices back to Match objects with proper scoring
|
||||
const results: Match[] = matchingIndices.map((index, order) => ({
|
||||
action: throttledFiltered[index],
|
||||
score: matchingIndices.length - order, // Higher score for better ranked matches
|
||||
}));
|
||||
const results: Match[] = matchingIndices.map((index, order) => {
|
||||
const name = throttledFiltered[index].name;
|
||||
const fullNameMatch = name.toLowerCase() === throttledSearch.toLowerCase();
|
||||
let score = matchingIndices.length - order; // Higher score for better ranked matches
|
||||
if (fullNameMatch) {
|
||||
score += 100; // Bumping for exact matches
|
||||
}
|
||||
return {
|
||||
action: throttledFiltered[index],
|
||||
score,
|
||||
};
|
||||
});
|
||||
|
||||
return results;
|
||||
}, [throttledFiltered, throttledSearch]);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Bumped to way higher value, to give it more weight when searching
|
||||
export const RECENT_SCOPES_PRIORITY = 50;
|
||||
export const SCOPES_PRIORITY = 8;
|
||||
export const RECENT_SCOPES_PRIORITY = 7;
|
||||
export const RECENT_DASHBOARDS_PRIORITY = 6;
|
||||
export const ACTIONS_PRIORITY = 5;
|
||||
export const DEFAULT_PRIORITY = 4;
|
||||
|
||||
Reference in New Issue
Block a user