Be able to mark a selection via the action, because that's handy!

This commit is contained in:
Mike Griese
2022-03-24 10:11:10 -05:00
parent c9bbeaa2ac
commit d364eb4d4e
5 changed files with 33 additions and 10 deletions

View File

@@ -1808,7 +1808,19 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
::Microsoft::Console::VirtualTerminal::DispatchTypes::ScrollMark m{};
m.color = til::color{ mark.Color };
_terminal->AddMark(m);
if (HasSelection())
{
m.start = til::point{ _terminal->GetSelectionAnchor() };
m.end = til::point{ _terminal->GetSelectionEnd() };
}
else
{
m.start = m.end = til::point{ _terminal->GetTextBuffer().GetCursor().GetPosition() };
}
// The version of this that only accepts a ScrollMark is buffer2
_terminal->AddMark(m, m.start, m.end);
}
void ControlCore::ClearMark() { _terminal->ClearMark(); }
void ControlCore::ClearAllMarks() { _terminal->ClearAllMarks(); }

View File

@@ -740,7 +740,6 @@ bool Terminal::SendCharEvent(const wchar_t ch, const WORD scanCode, const Contro
vkey = _VirtualKeyFromCharacter(ch);
}
if (_autoMarkPrompts && vkey == VK_RETURN && !_inAltBuffer())
{
DispatchTypes::ScrollMark mark;
@@ -1446,6 +1445,21 @@ const std::vector<Microsoft::Console::VirtualTerminal::DispatchTypes::ScrollMark
return _scrollMarks;
}
void Terminal::AddMark(const Microsoft::Console::VirtualTerminal::DispatchTypes::ScrollMark& mark,
const til::point& start,
const til::point& end)
{
DispatchTypes::ScrollMark m = mark;
m.start = start;
m.end = end;
// // m.timestamp = now()
_scrollMarks.push_back(m);
// Tell the control that the scrollbar has somehow changed. Used as a hack.
_NotifyScrollEvent();
}
void Terminal::ClearMark()
{
// TODO! just look for one where the cursor is, or where the selection is

View File

@@ -95,6 +95,9 @@ public:
const RenderSettings& GetRenderSettings() const noexcept { return _renderSettings; };
const std::vector<Microsoft::Console::VirtualTerminal::DispatchTypes::MenuEntry>& GetMenu() const;
const std::vector<Microsoft::Console::VirtualTerminal::DispatchTypes::ScrollMark>& GetScrollMarks() const;
void AddMark(const Microsoft::Console::VirtualTerminal::DispatchTypes::ScrollMark& mark,
const til::point& start,
const til::point& end);
#pragma region ITerminalApi
// These methods are defined in TerminalApi.cpp

View File

@@ -706,13 +706,6 @@ void Terminal::AddToMenu(const Microsoft::Console::VirtualTerminal::DispatchType
void Terminal::AddMark(const Microsoft::Console::VirtualTerminal::DispatchTypes::ScrollMark& mark)
{
DispatchTypes::ScrollMark m = mark;
// m.timestamp = now()
const til::point cursorPos{ _activeBuffer().GetCursor().GetPosition() };
m.start = m.end = cursorPos;
_scrollMarks.push_back(m);
// Tell the control that the scrollbar has somehow changed. Used as a hack.
_NotifyScrollEvent();
AddMark(mark, cursorPos, cursorPos);
}

View File

@@ -561,6 +561,7 @@ bool TerminalDispatch::DoITerm2Action(const std::wstring_view string)
DispatchTypes::ScrollMark mark;
mark.category = DispatchTypes::MarkCategory::Prompt;
mark.color = til::color(255, 255, 255); // should this be configurable?
// mark.start = mark.end = til::point{ _terminalApi.GetCursorPosition() };
_terminalApi.AddMark(mark);
return true;
}