Skip to content

Commit d8b5a48

Browse files
lheckerDHowett
authored andcommitted
Avoid scrolling when the search is open (#19775)
When text scrolls in and out of view, depending on the length of the scrollback and latency of input, `GetSearchHighlightFocused` would change which would trigger a `ScrollToSearchHighlight` call. This PR changes the behavior such that only actively changing the search mask triggers a search (typing text or pressing enter). Closes #19754 ## Validation Steps Performed * Brining text in and out of view doesn't scroll ✅ * Toggling the aA button scrolls results into view ✅ (cherry picked from commit 71409f8) Service-Card-Id: PVTI_lADOAF3p4s4BBcTlzgkLCdk Service-Version: 1.24
1 parent 8889180 commit d8b5a48

File tree

4 files changed

+46
-26
lines changed

4 files changed

+46
-26
lines changed

src/cascadia/TerminalControl/ControlCore.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,7 +1684,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
16841684
// - resetOnly: If true, only Reset() will be called, if anything. FindNext() will never be called.
16851685
// Return Value:
16861686
// - <none>
1687-
SearchResults ControlCore::Search(SearchRequest request)
1687+
SearchResults ControlCore::Search(const SearchRequest& request)
16881688
{
16891689
const auto lock = _terminal->LockForWriting();
16901690

@@ -1693,15 +1693,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation
16931693
WI_SetFlagIf(flags, SearchFlag::RegularExpression, request.RegularExpression);
16941694
const auto searchInvalidated = _searcher.IsStale(*_terminal.get(), request.Text, flags);
16951695

1696-
if (searchInvalidated || !request.ResetOnly)
1696+
if (searchInvalidated || request.ExecuteSearch)
16971697
{
16981698
std::vector<til::point_span> oldResults;
1699-
til::point_span oldFocused;
1700-
1701-
if (const auto focused = _terminal->GetSearchHighlightFocused())
1702-
{
1703-
oldFocused = *focused;
1704-
}
17051699

17061700
if (searchInvalidated)
17071701
{
@@ -1710,18 +1704,18 @@ namespace winrt::Microsoft::Terminal::Control::implementation
17101704
_terminal->SetSearchHighlights(_searcher.Results());
17111705
}
17121706

1713-
if (!request.ResetOnly)
1707+
if (request.ExecuteSearch)
17141708
{
17151709
_searcher.FindNext(!request.GoForward);
17161710
}
17171711

17181712
_terminal->SetSearchHighlightFocused(gsl::narrow<size_t>(std::max<ptrdiff_t>(0, _searcher.CurrentMatch())));
17191713
_renderer->TriggerSearchHighlight(oldResults);
1714+
}
17201715

1721-
if (const auto focused = _terminal->GetSearchHighlightFocused(); focused && *focused != oldFocused)
1722-
{
1723-
_terminal->ScrollToSearchHighlight(request.ScrollOffset);
1724-
}
1716+
if (request.ScrollIntoView)
1717+
{
1718+
_terminal->ScrollToSearchHighlight(request.ScrollOffset);
17251719
}
17261720

17271721
int32_t totalMatches = 0;

src/cascadia/TerminalControl/ControlCore.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
228228
void SetSelectionAnchor(const til::point position);
229229
void SetEndSelectionPoint(const til::point position);
230230

231-
SearchResults Search(SearchRequest request);
231+
SearchResults Search(const SearchRequest& request);
232232
const std::vector<til::point_span>& SearchResultRows() const noexcept;
233233
void ClearSearch();
234234

src/cascadia/TerminalControl/ControlCore.idl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ namespace Microsoft.Terminal.Control
5555
Boolean GoForward;
5656
Boolean CaseSensitive;
5757
Boolean RegularExpression;
58-
Boolean ResetOnly;
58+
Boolean ExecuteSearch;
59+
Boolean ScrollIntoView;
5960
Int32 ScrollOffset;
6061
};
6162

src/cascadia/TerminalControl/TermControl.cpp

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,15 @@ namespace winrt::Microsoft::Terminal::Control::implementation
718718
}
719719
else
720720
{
721-
const auto request = SearchRequest{ _searchBox->Text(), goForward, _searchBox->CaseSensitive(), _searchBox->RegularExpression(), false, _searchScrollOffset };
722-
_handleSearchResults(_core.Search(request));
721+
_handleSearchResults(_core.Search(SearchRequest{
722+
.Text = _searchBox->Text(),
723+
.GoForward = goForward,
724+
.CaseSensitive = _searchBox->CaseSensitive(),
725+
.RegularExpression = _searchBox->RegularExpression(),
726+
.ExecuteSearch = true,
727+
.ScrollIntoView = true,
728+
.ScrollOffset = _searchScrollOffset,
729+
}));
723730
}
724731
}
725732

@@ -753,8 +760,15 @@ namespace winrt::Microsoft::Terminal::Control::implementation
753760
{
754761
if (_searchBox && _searchBox->IsOpen())
755762
{
756-
const auto request = SearchRequest{ text, goForward, caseSensitive, regularExpression, false, _searchScrollOffset };
757-
_handleSearchResults(_core.Search(request));
763+
_handleSearchResults(_core.Search(SearchRequest{
764+
.Text = text,
765+
.GoForward = goForward,
766+
.CaseSensitive = caseSensitive,
767+
.RegularExpression = regularExpression,
768+
.ExecuteSearch = true,
769+
.ScrollIntoView = true,
770+
.ScrollOffset = _searchScrollOffset,
771+
}));
758772
}
759773
}
760774

@@ -773,11 +787,15 @@ namespace winrt::Microsoft::Terminal::Control::implementation
773787
{
774788
if (_searchBox && _searchBox->IsOpen())
775789
{
776-
// We only want to update the search results based on the new text. Set
777-
// `resetOnly` to true so we don't accidentally update the current match index.
778-
const auto request = SearchRequest{ text, goForward, caseSensitive, regularExpression, true, _searchScrollOffset };
779-
const auto result = _core.Search(request);
780-
_handleSearchResults(result);
790+
_handleSearchResults(_core.Search(SearchRequest{
791+
.Text = text,
792+
.GoForward = goForward,
793+
.CaseSensitive = caseSensitive,
794+
.RegularExpression = regularExpression,
795+
.ExecuteSearch = false,
796+
.ScrollIntoView = true,
797+
.ScrollOffset = _searchScrollOffset,
798+
}));
781799
}
782800
}
783801

@@ -3862,8 +3880,15 @@ namespace winrt::Microsoft::Terminal::Control::implementation
38623880
const auto goForward = _searchBox->GoForward();
38633881
const auto caseSensitive = _searchBox->CaseSensitive();
38643882
const auto regularExpression = _searchBox->RegularExpression();
3865-
const auto request = SearchRequest{ text, goForward, caseSensitive, regularExpression, true, _searchScrollOffset };
3866-
_handleSearchResults(_core.Search(request));
3883+
_handleSearchResults(_core.Search(SearchRequest{
3884+
.Text = text,
3885+
.GoForward = goForward,
3886+
.CaseSensitive = caseSensitive,
3887+
.RegularExpression = regularExpression,
3888+
.ExecuteSearch = false,
3889+
.ScrollIntoView = false,
3890+
.ScrollOffset = _searchScrollOffset,
3891+
}));
38673892
}
38683893

38693894
void TermControl::_handleSearchResults(SearchResults results)

0 commit comments

Comments
 (0)