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

Let marks be cleared by clear (and friends) #15686

Merged
merged 14 commits into from Jul 18, 2023
Merged

Conversation

zadjii-msft
Copy link
Member

Summary of the Pull Request

Move scroll marks to TextBuffer, so they can be cleared by EraseInDisplay and EraseScrollback.

Also removes the namespacing on them.

References and Relevant Issues

Validation Steps Performed

  • cls works
  • Clear-Host works
  • clear works
  • the "Clear buffer" action works
  • They work when there's marks above the current viewport, and clear the scrollback
  • they work if you clear multiple "pages" of output, then scroll back to where marks previously were
  • resizing doesn't totally destroy the marks

PR Checklist

@microsoft-github-policy-service microsoft-github-policy-service bot added Issue-Bug It either shouldn't be doing this or needs an investigation. Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Product-Terminal The new Windows Terminal. labels Jul 10, 2023
Copy link
Member

@lhecker lhecker left a comment

Choose a reason for hiding this comment

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

✅ because it works just like before, but...

If you don't mind, I think it would be better if you did add early-returns (if (_marks.empty()) return;) to all of the relevant functions. This makes it essentially cost free for OpenConsole and conhost (we could also use feature flags, but I'm personally impartial about that).

And additionally if the GetMarks function that returns a mutable reference could be removed. Reading through the changes I think this should be possible by adding:

  • AddMark(const ScrollMark& m, bool fromUi) (I forgot, what does fromUi do?)
  • UpdatePromptEnd(til::point end) (this can create the prompt mark if it doesn't already exist)
  • UpdateCommandEnd(til::point end) (same here)
  • ...

Basically, it would move more code from Terminal into TextBuffer, but that would IMO be very beneficial for long term maintenance once we aren't working here anymore. It would also make future improvements simpler, because it decouples the way marks are stored from their (internal) API.

src/cascadia/TerminalCore/Terminal.cpp Outdated Show resolved Hide resolved
src/buffer/out/textBuffer.cpp Outdated Show resolved Hide resolved
src/buffer/out/textBuffer.hpp Outdated Show resolved Hide resolved
Comment on lines +461 to +462
auto& marks{ _activeBuffer().GetMarks() };
const auto hasScrollMarks = marks.size() > 0;
Copy link
Member

Choose a reason for hiding this comment

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

For instance, you can move this check into ScrollMarks itself.

src/terminal/adapter/adaptDispatch.cpp Outdated Show resolved Hide resolved
[](const DispatchTypes::ScrollMark& m) -> bool { return !m.HasOutput(); },
[](const DispatchTypes::ScrollMark& m) { return til::point_span{ *m.commandEnd, *m.outputEnd }; });
[](const ::ScrollMark& m) -> bool { return !m.HasOutput(); },
[](const ::ScrollMark& m) { return til::point_span{ *m.commandEnd, *m.outputEnd }; });
Copy link
Member

Choose a reason for hiding this comment

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

You could use auto here.

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 promoting Leonard's concerns into a block to signal agreement 😄

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jul 10, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jul 13, 2023
@zadjii-msft zadjii-msft requested a review from DHowett July 17, 2023 12:36
Copy link
Member

@lhecker lhecker left a comment

Choose a reason for hiding this comment

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

Exactly what I had in mind!

src/buffer/out/textBuffer.cpp Outdated Show resolved Hide resolved
src/buffer/out/textBuffer.cpp Outdated Show resolved Hide resolved
src/buffer/out/textBuffer.cpp Outdated Show resolved Hide resolved
@zadjii-msft zadjii-msft requested a review from DHowett July 18, 2023 19:31
@@ -1359,7 +1359,7 @@ void Terminal::AddMark(const ScrollMark& mark,
m.end = end;

// If the mark came from the user adding a mark via the UI, don't make it the active prompt mark.
_activeBuffer().AddMark(m, !fromUi);
fromUi ? _activeBuffer().AddMark(m) : _activeBuffer().StartPromptMark(m);
Copy link
Member

Choose a reason for hiding this comment

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

It is very rare that using a ternary like this is the right thing to do.

Copy link
Member Author

Choose a reason for hiding this comment

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

yea that felt dirty to write

Comment on lines 2923 to 2928
void TextBuffer::StartPromptMark(const ScrollMark& m)
{
if (activeMark)
{
_marks.push_back(m);
}
else
{
_marks.insert(_marks.begin(), m);
}
_marks.push_back(m);
}
void TextBuffer::AddMark(const ScrollMark& m)
{
Copy link
Member

Choose a reason for hiding this comment

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

I still don't understand why "prompt mark" is "end of the entire list of marks" and "add mark" is the "beginning". I was hoping to find some clarity... but can you please just explain the guiding principle here?

Copy link
Member

Choose a reason for hiding this comment

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

Reading other comments, I understand that "AddMark" is "add a mark that is not the active mark" and "StartPromptMark" is "add a mark that IS the active mark" 😄

@github-actions

This comment has been minimized.

@DHowett DHowett enabled auto-merge (squash) July 18, 2023 20:43
@DHowett DHowett merged commit b4042ea into main Jul 18, 2023
14 of 15 checks passed
@DHowett DHowett deleted the dev/migrie/b/clear-marks branch July 18, 2023 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Scrollbar marks for shell integration do not clear when you use clear/cls commands
3 participants