Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix search constantly triggering a scroll #17132

Merged
merged 4 commits into from Apr 30, 2024

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Apr 25, 2024

This addresses a review comment left by tusharsnx in #17092 which I
forgot to fix before merging the PR. The fix itself is somewhat simple:
Terminal::SetSearchHighlightFocused triggers a scroll if the target
is outside of the current (scrolled) viewport and avoiding the call
unless necessary fixes it. To do it properly though, I've split up
Search::ResetIfStale into IsStale and Reset. Now we can properly
detect staleness in advance and branch out the search reset cleanly.

Additionally, I've taken the liberty to replace the IVector in
SearchResultRows with a direct const std::vector& into Searcher.
This removes a bunch of code and makes it faster to boot.

Validation Steps Performed

  • Print lots of text
  • Search a common letter
  • Scroll up
  • Doesn't scroll back down ✅
  • Hold enter to search more occurrences scrolls up as needed ✅
  • showMarksOnScrollbar still works ✅

@lhecker lhecker added Issue-Bug It either shouldn't be doing this or needs an investigation. Area-User Interface Issues pertaining to the user interface of the Console or Terminal Product-Terminal The new Windows Terminal. Priority-1 A description (P1) labels Apr 25, 2024
@DHowett
Copy link
Member

DHowett commented Apr 25, 2024

the build is highly imploded, so I may not review it yet ;P

src/buffer/out/search.cpp Outdated Show resolved Hide resolved
@DHowett
Copy link
Member

DHowett commented Apr 26, 2024

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

{
_terminal->SetSearchHighlightFocused(gsl::narrow<size_t>(idx));
}
_renderer->TriggerSearchHighlight(oldResults);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't oldResults be empty if we aren't invalidating? i guess I don't understand

Copy link
Member Author

@lhecker lhecker Apr 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean what happens if IsStale() returned false and we didn't call Reset()?
TriggerSearchHighlight is basically a "refresh all these areas" call. Normally we need to refresh all current areas, which is why oldResults is empty. It gets the current areas directly from IRenderData (previously set by SetSearchHighlights). During a reset oldResults contains the previous areas as well, since those aren't highlighted anymore = dirty.

Now that I think about it, I think we could also just remove the parameter to TriggerSearchHighlight and simply call it once before calling Reset() (= invalidate all the old highlights) and then once after (= all the new and current highlights).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I think about it, I think we could also just remove the parameter to TriggerSearchHighlight and simply call it once before calling Reset() (= invalidate all the old highlights) and then once after (= all the new and current highlights).

Nice 😃

TriggerSearchHighlight() also isn't completely correct in that the old highlights are supposed to be invalidated w.r.t old line renditions, but we currently don't store old line renditions so we're just using the current line renditions. I'm sure this can be fixed with buffer snapshot based rendering where we would pass in the line rendition from the current snapshot of the buffer that render engine has access to.

@zadjii-msft zadjii-msft added this to the Terminal v1.21 milestone Apr 29, 2024
@@ -1654,30 +1654,41 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// - text: the text to search
// - goForward: boolean that represents if the current search direction is forward
// - caseSensitive: boolean that represents if the current search is case sensitive
// - resetOnly: If true, only Reset() will be called, if anything. FindNext() will never be called.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// - resetOnly: If true, only Reset() will be called, if anything. FindNext() will never be called.
// - resetOnly: If true, only Search::IsStale() will be called, if anything. FindNext() will never be called.

right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, actually the comment is correct, but the boolean logic inside the function is very difficult to read. Basically, if resetOnly is true then if (searchInvalidated || !resetOnly) is only entered if searchInvalidated is true. If searchInvalidated is true then only Reset() will be called.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yea that's hard to parse

Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm in. Let's do it.

@zadjii-msft zadjii-msft added this pull request to the merge queue Apr 30, 2024
Merged via the queue into main with commit 32fbb16 Apr 30, 2024
20 checks passed
@zadjii-msft zadjii-msft deleted the dev/lhecker/17073-search-highlights-fixup branch April 30, 2024 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-User Interface Issues pertaining to the user interface of the Console or Terminal Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants