@@ -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
}
@@ -601,7 +603,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
601
603
}
602
604
603
605
// Method Description:
604
- // - The handler for the "search criteria changed" event. Clears selection and initiates a new search.
606
+ // - The handler for the "search criteria changed" event. Initiates a new search.
605
607
// Arguments:
606
608
// - text: the text to search
607
609
// - goForward: indicates whether the search should be performed forward (if set to true) or backward
@@ -614,7 +616,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation
614
616
{
615
617
if (_searchBox && _searchBox->Visibility () == Visibility::Visible)
616
618
{
617
- _handleSearchResults (_core.Search (text, goForward, caseSensitive, false ));
619
+ // We only want to update the search results based on the new text. Set
620
+ // `resetOnly` to true so we don't accidentally update the current match index.
621
+ const auto result = _core.Search (text, goForward, caseSensitive, true );
622
+ _handleSearchResults (result);
618
623
}
619
624
}
620
625
@@ -632,6 +637,19 @@ namespace winrt::Microsoft::Terminal::Control::implementation
632
637
_searchBox->Close ();
633
638
_core.ClearSearch ();
634
639
640
+ // Clear search highlights scrollmarks (by triggering an update after closing the search box)
641
+ if (_showMarksInScrollbar)
642
+ {
643
+ const auto scrollBar = ScrollBar ();
644
+ ScrollBarUpdate update{
645
+ .newValue = scrollBar.Value (),
646
+ .newMaximum = scrollBar.Maximum (),
647
+ .newMinimum = scrollBar.Minimum (),
648
+ .newViewportSize = scrollBar.ViewportSize (),
649
+ };
650
+ _updateScrollBar->Run (update);
651
+ }
652
+
635
653
// Set focus back to terminal control
636
654
this ->Focus (FocusState::Programmatic);
637
655
}
@@ -3593,7 +3611,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
3593
3611
3594
3612
void TermControl::_refreshSearch ()
3595
3613
{
3596
- if (!_searchBox || _searchBox->Visibility () != Visibility::Visible )
3614
+ if (!_searchBox || ! _searchBox->IsOpen () )
3597
3615
{
3598
3616
return ;
3599
3617
}
@@ -3616,7 +3634,15 @@ namespace winrt::Microsoft::Terminal::Control::implementation
3616
3634
return ;
3617
3635
}
3618
3636
3619
- _searchBox->SetStatus (results.TotalMatches , results.CurrentMatch );
3637
+ // Only show status when we have a search term
3638
+ if (_searchBox->Text ().empty ())
3639
+ {
3640
+ _searchBox->ClearStatus ();
3641
+ }
3642
+ else
3643
+ {
3644
+ _searchBox->SetStatus (results.TotalMatches , results.CurrentMatch );
3645
+ }
3620
3646
3621
3647
if (results.SearchInvalidated )
3622
3648
{
0 commit comments