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
45 changes: 41 additions & 4 deletions src/buffer/out/textBuffer.cpp
Expand Up @@ -2873,10 +2873,6 @@ PointTree TextBuffer::GetPatterns(const til::CoordType firstRow, const til::Coor
return result;
}

std::vector<ScrollMark>& TextBuffer::GetMarks()
{
return _marks;
}
const std::vector<ScrollMark>& TextBuffer::GetMarks() const
{
return _marks;
Expand Down Expand Up @@ -2924,6 +2920,18 @@ void TextBuffer::ScrollMarks(const int delta)
_trimMarksOutsideBuffer();
}

void TextBuffer::AddMark(ScrollMark& m, const bool activeMark)
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
{
if (activeMark)
{
_marks.push_back(m);
}
else
{
_marks.insert(_marks.begin(), m);
}
}

void TextBuffer::_trimMarksOutsideBuffer()
{
const auto height = GetSize().Height();
Expand All @@ -2935,3 +2943,32 @@ void TextBuffer::_trimMarksOutsideBuffer()
}),
_marks.end());
}

void TextBuffer::UpdateCurrentPromptEnd(const til::point pos)
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
{
if (_marks.empty())
{
return;
}
auto& curr{ _marks.back() };
curr.end = pos;
}
void TextBuffer::UpdateCurrentCommandEnd(const til::point pos)
{
if (_marks.empty())
{
return;
}
auto& curr{ _marks.back() };
curr.commandEnd = pos;
}
void TextBuffer::UpdateCurrentOutputEnd(const til::point pos, ::MarkCategory category)
DHowett marked this conversation as resolved.
Show resolved Hide resolved
{
if (_marks.empty())
{
return;
}
auto& curr{ _marks.back() };
curr.outputEnd = pos;
curr.category = category;
}
7 changes: 5 additions & 2 deletions src/buffer/out/textBuffer.hpp
Expand Up @@ -64,7 +64,7 @@ namespace Microsoft::Console::Render
class Renderer;
}

enum class MarkCategory : size_t
enum class MarkCategory
{
Prompt = 0,
Error = 1,
Expand Down Expand Up @@ -263,11 +263,14 @@ class TextBuffer final
void CopyPatterns(const TextBuffer& OtherBuffer);
interval_tree::IntervalTree<til::point, size_t> GetPatterns(const til::CoordType firstRow, const til::CoordType lastRow) const;

std::vector<ScrollMark>& GetMarks();
const std::vector<ScrollMark>& GetMarks() const;
void ClearMarksInRange(const til::point start, const til::point end);
void ClearAllMarks() noexcept;
void ScrollMarks(const int delta);
void AddMark(ScrollMark& m, const bool activeMark);
void UpdateCurrentPromptEnd(const til::point pos);
void UpdateCurrentCommandEnd(const til::point pos);
void UpdateCurrentOutputEnd(const til::point pos, ::MarkCategory category);

private:
void _reserve(til::size screenBufferSize, const TextAttribute& defaultAttributes);
Expand Down
13 changes: 3 additions & 10 deletions src/cascadia/TerminalCore/Terminal.cpp
Expand Up @@ -1358,14 +1358,8 @@ void Terminal::AddMark(const ScrollMark& mark,
m.start = start;
m.end = end;

if (fromUi)
{
_activeBuffer().GetMarks().insert(_activeBuffer().GetMarks().begin(), m);
}
else
{
_activeBuffer().GetMarks().push_back(m);
}
// 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);

// Tell the control that the scrollbar has somehow changed. Used as a
// workaround to force the control to redraw any scrollbar marks
Expand Down Expand Up @@ -1409,8 +1403,7 @@ const std::vector<ScrollMark>& Terminal::GetScrollMarks() const noexcept
// We want to return _no_ marks when we're in the alt buffer, to effectively
// hide them. We need to return a reference, so we can't just ctor an empty
// list here just for when we're in the alt buffer.
static const std::vector<ScrollMark> _altBufferMarks{};
return _inAltBuffer() ? _altBufferMarks : _activeBuffer().GetMarks();
return _activeBuffer().GetMarks();
}

til::color Terminal::GetColorForMark(const ScrollMark& mark) const
Expand Down
9 changes: 4 additions & 5 deletions src/cascadia/TerminalCore/TerminalApi.cpp
Expand Up @@ -337,7 +337,7 @@ void Terminal::MarkCommandStart()
mark.category = MarkCategory::Prompt;
AddMark(mark, cursorPos, cursorPos, false);
}
_activeBuffer().GetMarks().back().end = cursorPos;
_activeBuffer().UpdateCurrentPromptEnd(cursorPos);
_currentPromptState = PromptState::Command;
}

Expand All @@ -363,7 +363,7 @@ void Terminal::MarkOutputStart()
mark.category = MarkCategory::Prompt;
AddMark(mark, cursorPos, cursorPos, false);
}
_activeBuffer().GetMarks().back().commandEnd = cursorPos;
_activeBuffer().UpdateCurrentCommandEnd(cursorPos);
_currentPromptState = PromptState::Output;
}

Expand Down Expand Up @@ -396,10 +396,9 @@ void Terminal::MarkCommandFinish(std::optional<unsigned int> error)
ScrollMark mark;
mark.category = MarkCategory::Prompt;
AddMark(mark, cursorPos, cursorPos, false);
_activeBuffer().GetMarks().back().commandEnd = cursorPos;
_activeBuffer().UpdateCurrentCommandEnd(cursorPos);
}
_activeBuffer().GetMarks().back().outputEnd = cursorPos;
_activeBuffer().GetMarks().back().category = category;
_activeBuffer().UpdateCurrentOutputEnd(cursorPos, category);
_currentPromptState = PromptState::None;
}

Expand Down
6 changes: 3 additions & 3 deletions src/terminal/adapter/adaptDispatch.cpp
Expand Up @@ -3145,11 +3145,11 @@ bool AdaptDispatch::_EraseScrollback()
auto& cursor = textBuffer.GetCursor();
const auto row = cursor.GetPosition().y;

// Scroll all the marks up. This will trim ones that are now "outside" the buffer
textBuffer.ScrollMarks(-top);
// Also clear all the marks below the new viewport position.
// Clear all the marks below the new viewport position.
textBuffer.ClearMarksInRange(til::point{ 0, height },
til::point{ bufferSize.width, bufferSize.height });
// Then scroll all the remaining marks up. This will trim ones that are now "outside" the buffer
textBuffer.ScrollMarks(-top);

// Scroll the viewport content to the top of the buffer.
textBuffer.ScrollRows(top, height, -top);
Expand Down