@@ -1339,6 +1339,10 @@ public void Search(string text)
1339
1339
if ( Searching ) return ;
1340
1340
if ( string . IsNullOrEmpty ( text ) ) return ;
1341
1341
1342
+ var term = text . ToLowerInvariant ( ) ;
1343
+ var terms = term . Split ( new [ ] { '*' } , StringSplitOptions . RemoveEmptyEntries ) ;
1344
+ if ( terms . Length == 0 ) return ;
1345
+
1342
1346
SearchTextBox . Text = text ;
1343
1347
SearchButton . Image = SearchGlobalButton . Image ;
1344
1348
SearchButton . Text = SearchGlobalButton . Text ;
@@ -1362,15 +1366,13 @@ public void Search(string text)
1362
1366
1363
1367
UpdateStatus ( "Searching..." ) ;
1364
1368
1365
- var term = text . ToLowerInvariant ( ) ;
1366
-
1367
1369
//Task.Run(() =>
1368
1370
//{
1369
1371
Searching = true ;
1370
1372
1371
1373
Cursor = Cursors . WaitCursor ;
1372
1374
1373
- var resultcount = RootFolder . Search ( term , this ) ;
1375
+ var resultcount = RootFolder . Search ( terms , this ) ;
1374
1376
1375
1377
if ( Searching )
1376
1378
{
@@ -3782,6 +3784,45 @@ private void MainListView_RetrieveVirtualItem(object sender, RetrieveVirtualItem
3782
3784
e . Item = lvi ;
3783
3785
}
3784
3786
3787
+ private void MainListView_SearchForVirtualItem ( object sender , SearchForVirtualItemEventArgs e )
3788
+ {
3789
+ if ( CurrentFiles == null ) return ;
3790
+ var term = e . Text ;
3791
+ if ( string . IsNullOrEmpty ( term ) ) return ;
3792
+ var terml = term . ToLowerInvariant ( ) ;
3793
+ var start = e . StartIndex ;
3794
+ var isprefix = true ; // e.IsPrefixSearch;
3795
+ var direction = e . Direction ;
3796
+ var up = ( direction == SearchDirectionHint . Up ) || ( direction == SearchDirectionHint . Left ) ;
3797
+ var icnt = CurrentFiles . Count ;
3798
+ var incr = up ? - 1 : 1 ;
3799
+ var i = start ;
3800
+ while ( ( i >= 0 ) && ( i < icnt ) )
3801
+ {
3802
+ var name = CurrentFiles [ i ] ? . Name ;
3803
+ if ( string . IsNullOrEmpty ( name ) == false )
3804
+ {
3805
+ if ( isprefix )
3806
+ {
3807
+ if ( name . StartsWith ( terml , StringComparison . InvariantCultureIgnoreCase ) )
3808
+ {
3809
+ e . Index = i ;
3810
+ return ;
3811
+ }
3812
+ }
3813
+ else
3814
+ {
3815
+ if ( name . ToLowerInvariant ( ) . Contains ( terml ) ) //they fixed this in .net8
3816
+ {
3817
+ e . Index = i ;
3818
+ return ;
3819
+ }
3820
+ }
3821
+ }
3822
+ i += incr ;
3823
+ }
3824
+ }
3825
+
3785
3826
private void MainListView_ColumnClick ( object sender , ColumnClickEventArgs e )
3786
3827
{
3787
3828
var newdir = SortDirection ;
@@ -4632,14 +4673,14 @@ public string GetToolText()
4632
4673
return Path ;
4633
4674
}
4634
4675
4635
- public int Search ( string term , ExploreForm form )
4676
+ public int Search ( string [ ] terms , ExploreForm form )
4636
4677
{
4637
4678
int resultcount = 0 ;
4638
4679
//if (!form.Searching) return resultcount;
4639
4680
4640
4681
form . UpdateStatus ( "Searching " + Path + "..." ) ;
4641
4682
4642
- if ( Name . ToLowerInvariant ( ) . Contains ( term ) )
4683
+ if ( SearchMatch ( Name . ToLowerInvariant ( ) , terms ) )
4643
4684
{
4644
4685
form . AddSearchResult ( new MainListItem ( this ) ) ;
4645
4686
resultcount ++ ;
@@ -4653,7 +4694,7 @@ public int Search(string term, ExploreForm form)
4653
4694
{
4654
4695
//if (!form.Searching) return resultcount;
4655
4696
var fi = new FileInfo ( file ) ;
4656
- if ( fi . Name . ToLowerInvariant ( ) . Contains ( term ) )
4697
+ if ( SearchMatch ( fi . Name . ToLowerInvariant ( ) , terms ) )
4657
4698
{
4658
4699
form . AddSearchResult ( new MainListItem ( file , rootpath , this ) ) ;
4659
4700
resultcount ++ ;
@@ -4666,7 +4707,7 @@ public int Search(string term, ExploreForm form)
4666
4707
{
4667
4708
//if (!form.Searching) return resultcount;
4668
4709
if ( file . NameLower . EndsWith ( ".rpf" ) ) continue ; //don't search rpf files..
4669
- if ( file . NameLower . Contains ( term ) )
4710
+ if ( SearchMatch ( file . NameLower , terms ) )
4670
4711
{
4671
4712
form . AddSearchResult ( new MainListItem ( file , rootpath , this ) ) ;
4672
4713
resultcount ++ ;
@@ -4679,7 +4720,7 @@ public int Search(string term, ExploreForm form)
4679
4720
foreach ( var child in Children )
4680
4721
{
4681
4722
//if (!form.Searching) return resultcount;
4682
- resultcount += child . Search ( term , form ) ;
4723
+ resultcount += child . Search ( terms , form ) ;
4683
4724
}
4684
4725
}
4685
4726
0 commit comments