Skip to content

Commit

Permalink
PRE-MERGE #17352 Fix some search highlights scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Jun 4, 2024
2 parents 274010f + 3d9d32b commit 1c8e996
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
13 changes: 12 additions & 1 deletion src/cascadia/TerminalControl/SearchBoxControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,18 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// search box remains in Visible state (though not really *visible*) during the
// first load. So, we only need to apply this check here (after checking that
// we're done initializing).
if (Visibility() == Visibility::Visible)
if (IsOpen())
{
callback();
return;
}

// Stop ongoing close animation if any
if (CloseAnimation().GetCurrentState() == Media::Animation::ClockState::Active)
{
CloseAnimation().Stop();
}

VisualStateManager::GoToState(*this, L"Opened", false);

// Call the callback only after we're in Opened state. Setting focus
Expand Down Expand Up @@ -196,6 +202,11 @@ namespace winrt::Microsoft::Terminal::Control::implementation
}
}

bool SearchBoxControl::IsOpen()
{
return Visibility() == Visibility::Visible && CloseAnimation().GetCurrentState() != Media::Animation::ClockState::Active;
}

winrt::hstring SearchBoxControl::Text()
{
return TextBox().Text();
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/SearchBoxControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void TextBoxKeyDown(const winrt::Windows::Foundation::IInspectable& /*sender*/, const winrt::Windows::UI::Xaml::Input::KeyRoutedEventArgs& e);
void Open(std::function<void()> callback);
void Close();
bool IsOpen();

winrt::hstring Text();
bool GoForward();
Expand Down
38 changes: 32 additions & 6 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
}
}

if (_searchBox && _searchBox->Visibility() == Visibility::Visible)
if (_searchBox && _searchBox->IsOpen())
{
const auto core = winrt::get_self<ControlCore>(_core);
const auto& searchMatches = core->SearchResultRows();
Expand Down Expand Up @@ -567,6 +567,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// but since code paths differ, extra work is required to ensure correctness.
if (!_core.HasMultiLineSelection())
{
_core.SnapSearchResultToSelection(true);
const auto selectedLine{ _core.SelectedText(true) };
_searchBox->PopulateTextbox(selectedLine);
}
Expand All @@ -583,13 +584,14 @@ namespace winrt::Microsoft::Terminal::Control::implementation
}
}

// This is called when a Find Next/Previous Match action is triggered.
void TermControl::SearchMatch(const bool goForward)
{
if (_IsClosing())
{
return;
}
if (!_searchBox || _searchBox->Visibility() != Visibility::Visible)
if (!_searchBox || !_searchBox->IsOpen())
{
CreateSearchBoxControl();
}
Expand Down Expand Up @@ -631,7 +633,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
}

// Method Description:
// - The handler for the "search criteria changed" event. Clears selection and initiates a new search.
// - The handler for the "search criteria changed" event. Initiates a new search.
// Arguments:
// - text: the text to search
// - goForward: indicates whether the search should be performed forward (if set to true) or backward
Expand All @@ -645,7 +647,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
if (_searchBox && _searchBox->Visibility() == Visibility::Visible)
{
_handleSearchResults(_core.Search(text, goForward, caseSensitive, regularExpression, false));
// We only want to update the search results based on the new text. Set
// `resetOnly` to true so we don't accidentally update the current match index.
const auto result = _core.Search(text, goForward, caseSensitive, regularExpression, true);
_handleSearchResults(result);
}
}

Expand All @@ -663,6 +668,19 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_searchBox->Close();
_core.ClearSearch();

// Clear search highlights scroll marks (by triggering an update after closing the search box)
if (_showMarksInScrollbar)
{
const auto scrollBar = ScrollBar();
ScrollBarUpdate update{
.newValue = scrollBar.Value(),
.newMaximum = scrollBar.Maximum(),
.newMinimum = scrollBar.Minimum(),
.newViewportSize = scrollBar.ViewportSize(),
};
_updateScrollBar->Run(update);
}

// Set focus back to terminal control
this->Focus(FocusState::Programmatic);
}
Expand Down Expand Up @@ -3646,7 +3664,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation

void TermControl::_refreshSearch()
{
if (!_searchBox || _searchBox->Visibility() != Visibility::Visible)
if (!_searchBox || !_searchBox->IsOpen())
{
return;
}
Expand All @@ -3670,7 +3688,15 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return;
}

_searchBox->SetStatus(results.TotalMatches, results.CurrentMatch, results.SearchRegexInvalid);
// Only show status when we have a search term
if (_searchBox->Text().empty())
{
_searchBox->ClearStatus();
}
else
{
_searchBox->SetStatus(results.TotalMatches, results.CurrentMatch, results.SearchRegexInvalid);
}

if (results.SearchInvalidated)
{
Expand Down

1 comment on commit 1c8e996

@github-actions
Copy link

Choose a reason for hiding this comment

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

@check-spelling-bot Report

🔴 Please review

See the 📜action log or 📝 job summary for details.

Unrecognized words (1)

Unregistering

Previously acknowledged words that are now absent EJO unregistering XWalk YWalk 🫥
Some files were automatically ignored 🙈

These sample patterns would exclude them:

^\Qsrc/cascadia/TerminalControl/Microsoft.Management.Deployment.winmd\E$

You should consider adding them to:

.github/actions/spelling/excludes.txt

File matching is via Perl regular expressions.

To check these files, more of their words need to be in the dictionary than not. You can use patterns.txt to exclude portions, add items to the dictionary (e.g. by adding them to allow.txt), or fix typos.

To accept these unrecognized words as correct and remove the previously acknowledged and now absent words and update file exclusions, you could run the following commands

... in a clone of the [email protected]:microsoft/terminal.git repository
on the selfhost-1.22-bugbash-2024-06-04 branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.22/apply.pl' |
perl - 'https://github.com/microsoft/terminal/actions/runs/9365896402/attempts/1'
Available 📚 dictionaries could cover words (expected and unrecognized) not in the 📘 dictionary

This includes both expected items (2223) from .github/actions/spelling/expect/04cdb9b77d6827c0202f51acd4205b017015bfff.txt
.github/actions/spelling/expect/alphabet.txt
.github/actions/spelling/expect/expect.txt
.github/actions/spelling/expect/web.txt and unrecognized words (1)

Dictionary Entries Covers Uniquely
cspell:cpp/src/lang-jargon.txt 11 1 1
cspell:swift/src/swift.txt 53 1 1
cspell:gaming-terms/dict/gaming-terms.txt 59 1 1
cspell:monkeyc/src/monkeyc_keywords.txt 123 1 1
cspell:cryptocurrencies/cryptocurrencies.txt 125 1 1

Consider adding them (in .github/workflows/spelling2.yml) for uses: check-spelling/[email protected] in its with:

      with:
        extra_dictionaries:
          cspell:cpp/src/lang-jargon.txt
          cspell:swift/src/swift.txt
          cspell:gaming-terms/dict/gaming-terms.txt
          cspell:monkeyc/src/monkeyc_keywords.txt
          cspell:cryptocurrencies/cryptocurrencies.txt

To stop checking additional dictionaries, add (in .github/workflows/spelling2.yml) for uses: check-spelling/[email protected] in its with:

check_extra_dictionaries: ''
Errors (2)

See the 📜action log or 📝 job summary for details.

❌ Errors Count
ℹ️ binary-file 1
❌ ignored-expect-variant 4

See ❌ Event descriptions for more information.

✏️ Contributor please read this

By default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.

If the listed items are:

  • ... misspelled, then please correct them instead of using the command.
  • ... names, please add them to .github/actions/spelling/allow/names.txt.
  • ... APIs, you can add them to a file in .github/actions/spelling/allow/.
  • ... just things you're using, please add them to an appropriate file in .github/actions/spelling/expect/.
  • ... tokens you only need in one place and shouldn't generally be used, you can add an item in an appropriate file in .github/actions/spelling/patterns/.

See the README.md in each directory for more information.

🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Please sign in to comment.