-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Conversation
There was a problem hiding this 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 doesfromUi
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.
auto& marks{ _activeBuffer().GetMarks() }; | ||
const auto hasScrollMarks = marks.size() > 0; |
There was a problem hiding this comment.
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.
[](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 }; }); |
There was a problem hiding this comment.
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.
There was a problem hiding this 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 😄
There was a problem hiding this 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!
@@ -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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
src/buffer/out/textBuffer.cpp
Outdated
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) | ||
{ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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" 😄
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
worksClear-Host
worksclear
worksPR Checklist