77using Avalonia . Controls . Primitives ;
88using Avalonia . Controls . Primitives . PopupPositioning ;
99using Avalonia . Input ;
10- using Avalonia . Media ;
1110using Avalonia . Threading ;
1211using FuzzySharp ;
1312using Microsoft . Extensions . DependencyInjection ;
1413using StabilityMatrix . Core . Extensions ;
1514using StabilityMatrix . Core . Helper . Cache ;
1615using StabilityMatrix . Core . Models ;
16+ using StabilityMatrix . Core . Models . Api . Comfy ;
1717using StabilityMatrix . Core . Models . Settings ;
1818using StabilityMatrix . Core . Services ;
1919
@@ -82,20 +82,21 @@ public BetterComboBox()
8282 . Subscribe ( OnInputReceived , _ => ResetSearchText ( ) ) ;
8383 legacySearchResetTimer . Tick += OnLegacySearchResetTimerTick ;
8484
85- legacyInputTextBlock = new TextBlock { Foreground = Brushes . White , FontSize = 13 } ;
85+ legacyInputTextBlock = new TextBlock { FontSize = 13 } ;
86+ legacyInputTextBlock . Bind (
87+ TextBlock . ForegroundProperty ,
88+ this . GetResourceObservable ( "ComboBoxForeground" )
89+ ) ;
90+ var popupBorder = new Border { Padding = new Thickness ( 8 , 4 ) , Child = legacyInputTextBlock } ;
91+ popupBorder . Bind ( Border . BackgroundProperty , this . GetResourceObservable ( "ComboBoxDropDownBackground" ) ) ;
8692 legacyInputPopup = new Popup
8793 {
8894 IsLightDismissEnabled = true ,
8995 Placement = PlacementMode . AnchorAndGravity ,
9096 PlacementAnchor = PopupAnchor . Bottom ,
9197 PlacementGravity = PopupGravity . Top ,
9298 VerticalOffset = - 6 ,
93- Child = new Border
94- {
95- Background = Brush . Parse ( "#333333" ) ,
96- Padding = new Thickness ( 8 , 4 ) ,
97- Child = legacyInputTextBlock ,
98- } ,
99+ Child = popupBorder ,
99100 } ;
100101
101102 if ( ! Design . IsDesignMode )
@@ -322,11 +323,11 @@ private void OnInputReceived(string input)
322323 if ( UseLegacyModelSearch )
323324 {
324325 var legacyMatch = FindLegacyMatch ( input ) ;
325- if ( legacyMatch is not null )
326- {
327- searchCache . Add ( input , legacyMatch ) ;
328- Dispatcher . UIThread . Post ( ( ) => SelectedItem = legacyMatch ) ;
329- }
326+ if ( legacyMatch is null )
327+ return ;
328+
329+ searchCache . Add ( input , legacyMatch ) ;
330+ Dispatcher . UIThread . Post ( ( ) => SelectedItem = legacyMatch ) ;
330331 return ;
331332 }
332333
@@ -392,7 +393,7 @@ private void ApplyFilter(string input)
392393
393394 private bool IsItemMatch ( object item , string query )
394395 {
395- var itemText = GetItemSearchText ( item ) ;
396+ var itemText = GetItemSearchText ( item , UseLegacyModelSearch ) ;
396397
397398 if ( UseLegacyModelSearch )
398399 {
@@ -412,29 +413,39 @@ private bool IsItemMatch(object item, string query)
412413 if ( string . IsNullOrWhiteSpace ( trimmedQuery ) )
413414 return null ;
414415
415- var enumMatch = Items
416- . OfType < Enum > ( )
417- . FirstOrDefault ( e =>
418- e . GetStringValue ( ) . Contains ( trimmedQuery , StringComparison . OrdinalIgnoreCase )
419- ) ;
420- if ( enumMatch is not null )
416+ object ? firstSearchTextMatch = null ;
417+
418+ foreach ( var item in Items )
421419 {
422- return enumMatch ;
420+ if ( item is Enum enumItem )
421+ {
422+ if ( enumItem . GetStringValue ( ) . Contains ( trimmedQuery , StringComparison . OrdinalIgnoreCase ) )
423+ {
424+ return enumItem ;
425+ }
426+ }
427+ else if ( firstSearchTextMatch is null && item is ISearchText or ComfySampler or ComfyScheduler )
428+ {
429+ if ( GetItemSearchText ( item , true ) . Contains ( trimmedQuery , StringComparison . OrdinalIgnoreCase ) )
430+ {
431+ firstSearchTextMatch = item ;
432+ }
433+ }
423434 }
424435
425- return Items
426- . OfType < ISearchText > ( )
427- . FirstOrDefault ( item =>
428- GetItemSearchText ( item ) . Contains ( trimmedQuery , StringComparison . OrdinalIgnoreCase )
429- ) ;
436+ return firstSearchTextMatch ;
430437 }
431438
432- private static string GetItemSearchText ( object item )
439+ private static string GetItemSearchText ( object item , bool useLegacySearch = false )
433440 {
434441 return item switch
435442 {
436- HybridModelFile hybridModel => hybridModel . DetailedSearchText ,
443+ HybridModelFile hybridModel => useLegacySearch
444+ ? hybridModel . SearchText
445+ : hybridModel . DetailedSearchText ,
437446 Enum enumItem => enumItem . GetStringValue ( ) ,
447+ ComfySampler sampler => $ "{ sampler . DisplayName } { sampler . Name } ",
448+ ComfyScheduler scheduler => $ "{ scheduler . DisplayName } { scheduler . Name } ",
438449 ISearchText searchable => searchable . SearchText ,
439450 _ => item . ToString ( ) ?? string . Empty ,
440451 } ;
0 commit comments