@@ -493,7 +493,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
493
493
}
494
494
}
495
495
496
- if (_searchBox && _searchBox->Visibility () == Visibility::Visible )
496
+ if (_searchBox && _searchBox->IsOpen () )
497
497
{
498
498
const auto core = winrt::get_self<ControlCore>(_core);
499
499
const auto & searchMatches = core->SearchResultRows ();
@@ -538,6 +538,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
538
538
// but since code paths differ, extra work is required to ensure correctness.
539
539
if (!_core.HasMultiLineSelection ())
540
540
{
541
+ _core.SnapSearchResultToSelection (true );
541
542
const auto selectedLine{ _core.SelectedText (true ) };
542
543
_searchBox->PopulateTextbox (selectedLine);
543
544
}
@@ -554,13 +555,14 @@ namespace winrt::Microsoft::Terminal::Control::implementation
554
555
}
555
556
}
556
557
558
+ // This is called when a Find Next/Previous Match action is triggered.
557
559
void TermControl::SearchMatch (const bool goForward)
558
560
{
559
561
if (_IsClosing ())
560
562
{
561
563
return ;
562
564
}
563
- if (!_searchBox || _searchBox->Visibility () != Visibility::Visible )
565
+ if (!_searchBox || ! _searchBox->IsOpen () )
564
566
{
565
567
CreateSearchBoxControl ();
566
568
}
@@ -602,7 +604,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
602
604
}
603
605
604
606
// Method Description:
605
- // - The handler for the "search criteria changed" event. Clears selection and initiates a new search.
607
+ // - The handler for the "search criteria changed" event. Initiates a new search.
606
608
// Arguments:
607
609
// - text: the text to search
608
610
// - goForward: indicates whether the search should be performed forward (if set to true) or backward
@@ -616,7 +618,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation
616
618
{
617
619
if (_searchBox && _searchBox->Visibility () == Visibility::Visible)
618
620
{
619
- _handleSearchResults (_core.Search (text, goForward, caseSensitive, regularExpression, false ));
621
+ // We only want to update the search results based on the new text. Set
622
+ // `resetOnly` to true so we don't accidentally update the current match index.
623
+ const auto result = _core.Search (text, goForward, caseSensitive, regularExpression, true );
624
+ _handleSearchResults (result);
620
625
}
621
626
}
622
627
@@ -634,6 +639,19 @@ namespace winrt::Microsoft::Terminal::Control::implementation
634
639
_searchBox->Close ();
635
640
_core.ClearSearch ();
636
641
642
+ // Clear search highlights scroll marks (by triggering an update after closing the search box)
643
+ if (_showMarksInScrollbar)
644
+ {
645
+ const auto scrollBar = ScrollBar ();
646
+ ScrollBarUpdate update{
647
+ .newValue = scrollBar.Value (),
648
+ .newMaximum = scrollBar.Maximum (),
649
+ .newMinimum = scrollBar.Minimum (),
650
+ .newViewportSize = scrollBar.ViewportSize (),
651
+ };
652
+ _updateScrollBar->Run (update);
653
+ }
654
+
637
655
// Set focus back to terminal control
638
656
this ->Focus (FocusState::Programmatic);
639
657
}
@@ -3595,7 +3613,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
3595
3613
3596
3614
void TermControl::_refreshSearch ()
3597
3615
{
3598
- if (!_searchBox || _searchBox->Visibility () != Visibility::Visible )
3616
+ if (!_searchBox || ! _searchBox->IsOpen () )
3599
3617
{
3600
3618
return ;
3601
3619
}
@@ -3619,7 +3637,15 @@ namespace winrt::Microsoft::Terminal::Control::implementation
3619
3637
return ;
3620
3638
}
3621
3639
3622
- _searchBox->SetStatus (results.TotalMatches , results.CurrentMatch , results.SearchRegexInvalid );
3640
+ // Only show status when we have a search term
3641
+ if (_searchBox->Text ().empty ())
3642
+ {
3643
+ _searchBox->ClearStatus ();
3644
+ }
3645
+ else
3646
+ {
3647
+ _searchBox->SetStatus (results.TotalMatches , results.CurrentMatch , results.SearchRegexInvalid );
3648
+ }
3623
3649
3624
3650
if (results.SearchInvalidated )
3625
3651
{
0 commit comments