@@ -29,37 +29,20 @@ export type SearchQualifierKey = keyof typeof SEARCH_QUALIFIERS;
2929export type SearchQualifier = ( typeof SEARCH_QUALIFIERS ) [ SearchQualifierKey ] ;
3030export type SearchPrefix = SearchQualifier [ 'prefix' ] ;
3131
32- export const QUALIFIERS : readonly SearchQualifier [ ] = Object . values (
32+ export const ALL_SEARCH_QUALIFIERS : readonly SearchQualifier [ ] = Object . values (
3333 SEARCH_QUALIFIERS ,
3434) as readonly SearchQualifier [ ] ;
3535
3636
37- export const BASE_QUALIFIERS : readonly SearchQualifier [ ] = QUALIFIERS . filter (
37+ export const BASE_SEARCH_QUALIFIERS : readonly SearchQualifier [ ] = ALL_SEARCH_QUALIFIERS . filter (
3838 ( q ) => ! q . requiresDetailsNotifications ,
3939) ;
4040
41- export const DETAILED_ONLY_QUALIFIERS : readonly SearchQualifier [ ] = QUALIFIERS . filter (
41+ export const DETAILED_ONLY_SEARCH_QUALIFIERS : readonly SearchQualifier [ ] = ALL_SEARCH_QUALIFIERS . filter (
4242 ( q ) => q . requiresDetailsNotifications ,
4343) ;
4444
4545
46- // Qualifier selection helpers (centralized to avoid duplicating logic in UI components)
47- export function getAvailableSearchQualifiers (
48- detailedNotificationsEnabled : boolean ,
49- ) : readonly SearchQualifier [ ] {
50- const all = Object . values ( SEARCH_QUALIFIERS ) as readonly SearchQualifier [ ] ;
51- if ( detailedNotificationsEnabled ) {
52- return all ;
53- }
54-
55- return all . filter ( ( q ) => ! q . requiresDetailsNotifications ) ;
56- }
57-
58- export const BASE_SEARCH_QUALIFIERS : readonly SearchQualifier [ ] =
59- getAvailableSearchQualifiers ( false ) ;
60- export const ALL_SEARCH_QUALIFIERS : readonly SearchQualifier [ ] =
61- getAvailableSearchQualifiers ( true ) ;
62-
6346export function hasIncludeSearchFilters ( settings : SettingsState ) {
6447 return settings . filterIncludeSearchTokens . length > 0 ;
6548}
@@ -68,15 +51,6 @@ export function hasExcludeSearchFilters(settings: SettingsState) {
6851 return settings . filterExcludeSearchTokens . length > 0 ;
6952}
7053
71- export function matchQualifierByPrefix ( token : string ) {
72- for ( const qualifier of QUALIFIERS ) {
73- if ( token . startsWith ( qualifier . prefix ) ) {
74- return qualifier ;
75- }
76- }
77- return null ;
78- }
79-
8054function stripPrefix ( token : string , qualifier : SearchQualifier ) {
8155 return token . slice ( qualifier . prefix . length ) . trim ( ) ;
8256}
@@ -88,17 +62,22 @@ export interface ParsedSearchToken {
8862}
8963
9064export function parseSearchToken ( token : string ) : ParsedSearchToken | null {
91- const qualifier = matchQualifierByPrefix ( token ) ;
92- if ( ! qualifier ) {
65+ if ( ! token ) {
9366 return null ;
9467 }
9568
96- const value = stripPrefix ( token , qualifier ) ;
97- if ( ! value ) {
98- return null ;
69+ for ( const qualifier of ALL_SEARCH_QUALIFIERS ) {
70+ if ( token . startsWith ( qualifier . prefix ) ) {
71+ const value = stripPrefix ( token , qualifier ) ;
72+
73+ if ( ! value ) {
74+ return null ; // prefix only
75+ }
76+
77+ return { qualifier, value, valueLower : value . toLowerCase ( ) } ;
78+ }
9979 }
100-
101- return { qualifier, value, valueLower : value . toLowerCase ( ) } ;
80+ return null ;
10281}
10382
10483// Normalize raw user input from the token text field into a SearchToken (string)
@@ -110,7 +89,7 @@ export function normalizeSearchInputToToken(raw: string): string | null {
11089 }
11190
11291 const lower = value . toLowerCase ( ) ;
113- const matchedQualifier = QUALIFIERS . find ( ( q ) => lower . startsWith ( q . prefix ) ) ;
92+ const matchedQualifier = ALL_SEARCH_QUALIFIERS . find ( ( q ) => lower . startsWith ( q . prefix ) ) ;
11493
11594 if ( ! matchedQualifier ) {
11695 return null ;
0 commit comments