Skip to content

Commit

Permalink
fix build (primarily PublicTerminalCore)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-zamora committed Sep 13, 2021
1 parent 0cc9bd0 commit 95967ec
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 64 deletions.
4 changes: 2 additions & 2 deletions src/cascadia/PublicTerminalCore/HwndTerminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,11 +549,11 @@ try

if (multiClickMapper == 3)
{
_terminal->MultiClickSelection(cursorPosition / fontSize, ::Terminal::SelectionExpansionMode::Line);
_terminal->MultiClickSelection(cursorPosition / fontSize, InternalSelectionExpansion::Line);
}
else if (multiClickMapper == 2)
{
_terminal->MultiClickSelection(cursorPosition / fontSize, ::Terminal::SelectionExpansionMode::Word);
_terminal->MultiClickSelection(cursorPosition / fontSize, InternalSelectionExpansion::Word);
}
else
{
Expand Down
41 changes: 37 additions & 4 deletions src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,40 @@ constexpr const auto TsfRedrawInterval = std::chrono::milliseconds(100);
// The minimum delay between updating the locations of regex patterns
constexpr const auto UpdatePatternLocationsInterval = std::chrono::milliseconds(500);

static constexpr InternalSelectionDirection ConvertToInternalSelectionDirection(winrt::Microsoft::Terminal::Core::SelectionDirection dir)
{
switch (dir)
{
default:
case winrt::Microsoft::Terminal::Core::SelectionDirection::Left:
return InternalSelectionDirection::Left;
case winrt::Microsoft::Terminal::Core::SelectionDirection::Right:
return InternalSelectionDirection::Right;
case winrt::Microsoft::Terminal::Core::SelectionDirection::Up:
return InternalSelectionDirection::Up;
case winrt::Microsoft::Terminal::Core::SelectionDirection::Down:
return InternalSelectionDirection::Down;
}
}

static constexpr InternalSelectionExpansion ConvertToInternalSelectionExpansion(winrt::Microsoft::Terminal::Core::SelectionExpansion mode)
{
switch (mode)
{
default:
case winrt::Microsoft::Terminal::Core::SelectionExpansion::Char:
return InternalSelectionExpansion::Char;
case winrt::Microsoft::Terminal::Core::SelectionExpansion::Word:
return InternalSelectionExpansion::Word;
case winrt::Microsoft::Terminal::Core::SelectionExpansion::Line:
return InternalSelectionExpansion::Line;
case winrt::Microsoft::Terminal::Core::SelectionExpansion::Viewport:
return InternalSelectionExpansion::Viewport;
case winrt::Microsoft::Terminal::Core::SelectionExpansion::Buffer:
return InternalSelectionExpansion::Buffer;
}
}

namespace winrt::Microsoft::Terminal::Control::implementation
{
// Helper static function to ensure that all ambiguous-width glyphs are reported as narrow.
Expand Down Expand Up @@ -937,7 +971,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
}

auto lock = _terminal->LockForWriting();
_terminal->UpdateSelection(direction, mode);
_terminal->UpdateSelection(ConvertToInternalSelectionDirection(direction), ConvertToInternalSelectionExpansion(mode));
_renderer->TriggerSelection();
return true;
}
Expand Down Expand Up @@ -1470,15 +1504,15 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
// If shift is pressed and there is a selection we extend it using
// the selection mode (expand the "end" selection point)
_terminal->SetSelectionEnd(terminalPosition, mode);
_terminal->SetSelectionEnd(terminalPosition, ConvertToInternalSelectionExpansion(mode));
selectionNeedsToBeCopied = true;
}
else if (mode != Core::SelectionExpansion::Char || shiftEnabled)
{
// If we are handling a double / triple-click or shift+single click
// we establish selection using the selected mode
// (expand both "start" and "end" selection points)
_terminal->MultiClickSelection(terminalPosition, mode);
_terminal->MultiClickSelection(terminalPosition, ConvertToInternalSelectionExpansion(mode));
selectionNeedsToBeCopied = true;
}

Expand Down Expand Up @@ -1572,5 +1606,4 @@ namespace winrt::Microsoft::Terminal::Control::implementation

return hstring(ss.str());
}

}
2 changes: 1 addition & 1 deletion src/cascadia/TerminalCore/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ WORD Terminal::_TakeVirtualKeyFromLastKeyEvent(const WORD scanCode) noexcept
return std::unique_lock{ _readWriteLock };
}

Viewport Terminal::_GetMutableViewport() const noexcept
Microsoft::Console::Types::Viewport Terminal::_GetMutableViewport() const noexcept
{
return _mutableViewport;
}
Expand Down
33 changes: 25 additions & 8 deletions src/cascadia/TerminalCore/Terminal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ namespace winrt::Microsoft::Terminal::Core
namespace Microsoft::Terminal::Core
{
class Terminal;

enum class InternalSelectionDirection
{
Left,
Right,
Up,
Down
};

enum class InternalSelectionExpansion
{
Char,
Word,
Line, // Mouse selection only! Not a setting!
Viewport,
Buffer
};
}

// fwdecl unittest classes
Expand Down Expand Up @@ -227,11 +244,11 @@ class Microsoft::Terminal::Core::Terminal final :

#pragma region TextSelection
// These methods are defined in TerminalSelection.cpp
void MultiClickSelection(const COORD viewportPos, winrt::Microsoft::Terminal::Core::SelectionExpansion expansionMode);
void MultiClickSelection(const COORD viewportPos, InternalSelectionExpansion expansionMode);
void SetSelectionAnchor(const COORD position);
void SetSelectionEnd(const COORD position, std::optional<winrt::Microsoft::Terminal::Core::SelectionExpansion> newExpansionMode = std::nullopt);
void SetSelectionEnd(const COORD position, std::optional<InternalSelectionExpansion> newExpansionMode = std::nullopt);
void SetBlockSelection(const bool isEnabled) noexcept;
void UpdateSelection(winrt::Microsoft::Terminal::Core::SelectionDirection direction, winrt::Microsoft::Terminal::Core::SelectionExpansion mode);
void UpdateSelection(InternalSelectionDirection direction, InternalSelectionExpansion mode);

const TextBuffer::TextAndColor RetrieveSelectedTextFromBuffer(bool trimTrailingWhitespace);
#pragma endregion
Expand Down Expand Up @@ -303,7 +320,7 @@ class Microsoft::Terminal::Core::Terminal final :
std::optional<SelectionAnchors> _selection;
bool _blockSelection;
std::wstring _wordDelimiters;
winrt::Microsoft::Terminal::Core::SelectionExpansion _multiClickSelectionMode;
InternalSelectionExpansion _multiClickSelectionMode;
#pragma endregion

// TODO: These members are not shared by an alt-buffer. They should be
Expand Down Expand Up @@ -370,10 +387,10 @@ class Microsoft::Terminal::Core::Terminal final :
std::tuple<COORD, COORD, bool> _PivotSelection(const COORD targetPos) const;
std::pair<COORD, COORD> _ExpandSelectionAnchors(std::pair<COORD, COORD> anchors) const;
COORD _ConvertToBufferCell(const COORD viewportPos) const;
void _MoveByChar(winrt::Microsoft::Terminal::Core::SelectionDirection direction, COORD& pos);
void _MoveByWord(winrt::Microsoft::Terminal::Core::SelectionDirection direction, COORD& pos);
void _MoveByViewport(winrt::Microsoft::Terminal::Core::SelectionDirection direction, COORD& pos);
void _MoveByBuffer(winrt::Microsoft::Terminal::Core::SelectionDirection direction, COORD& pos);
void _MoveByChar(InternalSelectionDirection direction, COORD& pos);
void _MoveByWord(InternalSelectionDirection direction, COORD& pos);
void _MoveByViewport(InternalSelectionDirection direction, COORD& pos);
void _MoveByBuffer(InternalSelectionDirection direction, COORD& pos);
#pragma endregion

Microsoft::Console::VirtualTerminal::SgrStack _sgrStack;
Expand Down
62 changes: 31 additions & 31 deletions src/cascadia/TerminalCore/TerminalSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const bool Terminal::IsBlockSelection() const noexcept
// Arguments:
// - viewportPos: the (x,y) coordinate on the visible viewport
// - expansionMode: the SelectionExpansion to dictate the boundaries of the selection anchors
void Terminal::MultiClickSelection(const COORD viewportPos, SelectionExpansion expansionMode)
void Terminal::MultiClickSelection(const COORD viewportPos, InternalSelectionExpansion expansionMode)
{
// set the selection pivot to expand the selection using SetSelectionEnd()
_selection = SelectionAnchors{};
Expand All @@ -127,7 +127,7 @@ void Terminal::SetSelectionAnchor(const COORD viewportPos)
_selection = SelectionAnchors{};
_selection->pivot = _ConvertToBufferCell(viewportPos);

_multiClickSelectionMode = SelectionExpansion::Char;
_multiClickSelectionMode = InternalSelectionExpansion::Char;
SetSelectionEnd(viewportPos);

_selection->start = _selection->pivot;
Expand All @@ -139,7 +139,7 @@ void Terminal::SetSelectionAnchor(const COORD viewportPos)
// Arguments:
// - viewportPos: the (x,y) coordinate on the visible viewport
// - newExpansionMode: overwrites the _multiClickSelectionMode for this function call. Used for ShiftClick
void Terminal::SetSelectionEnd(const COORD viewportPos, std::optional<SelectionExpansion> newExpansionMode)
void Terminal::SetSelectionEnd(const COORD viewportPos, std::optional<InternalSelectionExpansion> newExpansionMode)
{
if (!_selection.has_value())
{
Expand Down Expand Up @@ -216,15 +216,15 @@ std::pair<COORD, COORD> Terminal::_ExpandSelectionAnchors(std::pair<COORD, COORD
const auto bufferSize = _buffer->GetSize();
switch (_multiClickSelectionMode)
{
case SelectionExpansion::Line:
case InternalSelectionExpansion::Line:
start = { bufferSize.Left(), start.Y };
end = { bufferSize.RightInclusive(), end.Y };
break;
case SelectionExpansion::Word:
case InternalSelectionExpansion::Word:
start = _buffer->GetWordStart(start, _wordDelimiters);
end = _buffer->GetWordEnd(end, _wordDelimiters);
break;
case SelectionExpansion::Char:
case InternalSelectionExpansion::Char:
default:
// no expansion is necessary
break;
Expand All @@ -241,7 +241,7 @@ void Terminal::SetBlockSelection(const bool isEnabled) noexcept
_blockSelection = isEnabled;
}

void Terminal::UpdateSelection(SelectionDirection direction, SelectionExpansion mode)
void Terminal::UpdateSelection(InternalSelectionDirection direction, InternalSelectionExpansion mode)
{
// 1. Figure out which endpoint to update
// One of the endpoints is the pivot, signifying that the other endpoint is the one we want to move.
Expand All @@ -251,16 +251,16 @@ void Terminal::UpdateSelection(SelectionDirection direction, SelectionExpansion
// 2. Perform the movement
switch (mode)
{
case SelectionExpansion::Char:
case InternalSelectionExpansion::Char:
_MoveByChar(direction, targetPos);
break;
case SelectionExpansion::Word:
case InternalSelectionExpansion::Word:
_MoveByWord(direction, targetPos);
break;
case SelectionExpansion::Viewport:
case InternalSelectionExpansion::Viewport:
_MoveByViewport(direction, targetPos);
break;
case SelectionExpansion::Buffer:
case InternalSelectionExpansion::Buffer:
_MoveByBuffer(direction, targetPos);
break;
}
Expand All @@ -287,25 +287,25 @@ void Terminal::UpdateSelection(SelectionDirection direction, SelectionExpansion
}
}

void Terminal::_MoveByChar(SelectionDirection direction, COORD& pos)
void Terminal::_MoveByChar(InternalSelectionDirection direction, COORD& pos)
{
switch (direction)
{
case SelectionDirection::Left:
case InternalSelectionDirection::Left:
_buffer->GetSize().DecrementInBounds(pos);
pos = _buffer->GetGlyphStart(pos);
break;
case SelectionDirection::Right:
case InternalSelectionDirection::Right:
_buffer->GetSize().IncrementInBounds(pos);
pos = _buffer->GetGlyphEnd(pos);
break;
case SelectionDirection::Up:
case InternalSelectionDirection::Up:
{
const auto bufferSize{ _buffer->GetSize() };
pos = { pos.X, std::clamp(base::ClampSub<short, short>(pos.Y, 1).RawValue(), bufferSize.Top(), bufferSize.BottomInclusive()) };
break;
}
case SelectionDirection::Down:
case InternalSelectionDirection::Down:
{
const auto bufferSize{ _buffer->GetSize() };
pos = { pos.X, std::clamp(base::ClampAdd<short, short>(pos.Y, 1).RawValue(), bufferSize.Top(), bufferSize.BottomInclusive()) };
Expand All @@ -314,11 +314,11 @@ void Terminal::_MoveByChar(SelectionDirection direction, COORD& pos)
}
}

void Terminal::_MoveByWord(SelectionDirection direction, COORD& pos)
void Terminal::_MoveByWord(InternalSelectionDirection direction, COORD& pos)
{
switch (direction)
{
case SelectionDirection::Left:
case InternalSelectionDirection::Left:
const auto wordStartPos{ _buffer->GetWordStart(pos, _wordDelimiters) };
if (_buffer->GetSize().CompareInBounds(_selection->pivot, pos) < 0)
{
Expand All @@ -339,7 +339,7 @@ void Terminal::_MoveByWord(SelectionDirection direction, COORD& pos)
pos = wordStartPos;
}
break;
case SelectionDirection::Right:
case InternalSelectionDirection::Right:
const auto wordEndPos{ _buffer->GetWordEnd(pos, _wordDelimiters) };
if (_buffer->GetSize().CompareInBounds(pos, _selection->pivot) < 0)
{
Expand All @@ -360,36 +360,36 @@ void Terminal::_MoveByWord(SelectionDirection direction, COORD& pos)
pos = wordEndPos;
}
break;
case SelectionDirection::Up:
case InternalSelectionDirection::Up:
_MoveByChar(direction, pos);
pos = _buffer->GetWordStart(pos, _wordDelimiters);
break;
case SelectionDirection::Down:
case InternalSelectionDirection::Down:
_MoveByChar(direction, pos);
pos = _buffer->GetWordEnd(pos, _wordDelimiters);
break;
}
}

void Terminal::_MoveByViewport(SelectionDirection direction, COORD& pos)
void Terminal::_MoveByViewport(InternalSelectionDirection direction, COORD& pos)
{
const auto bufferSize{ _buffer->GetSize() };
switch (direction)
{
case SelectionDirection::Left:
case InternalSelectionDirection::Left:
pos = { bufferSize.Left(), pos.Y };
break;
case SelectionDirection::Right:
case InternalSelectionDirection::Right:
pos = { bufferSize.RightInclusive(), pos.Y };
break;
case SelectionDirection::Up:
case InternalSelectionDirection::Up:
{
const auto viewportHeight{ _mutableViewport.Height() };
const auto newY{ base::ClampSub<short, short>(pos.Y, viewportHeight) };
pos = newY < bufferSize.Top() ? bufferSize.Origin() : COORD{ pos.X, newY };
break;
}
case SelectionDirection::Down:
case InternalSelectionDirection::Down:
{
const auto viewportHeight{ _mutableViewport.Height() };
const auto mutableBottom{ _mutableViewport.BottomInclusive() };
Expand All @@ -400,17 +400,17 @@ void Terminal::_MoveByViewport(SelectionDirection direction, COORD& pos)
}
}

void Terminal::_MoveByBuffer(SelectionDirection direction, COORD& pos)
void Terminal::_MoveByBuffer(InternalSelectionDirection direction, COORD& pos)
{
const auto bufferSize{ _buffer->GetSize() };
switch (direction)
{
case SelectionDirection::Left:
case SelectionDirection::Up:
case InternalSelectionDirection::Left:
case InternalSelectionDirection::Up:
pos = bufferSize.Origin();
break;
case SelectionDirection::Right:
case SelectionDirection::Down:
case InternalSelectionDirection::Right:
case InternalSelectionDirection::Down:
pos = { bufferSize.RightInclusive(), _mutableViewport.BottomInclusive() };
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalCore/terminalrenderdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void Terminal::SelectNewRegion(const COORD coordStart, const COORD coordEnd)
realCoordEnd.Y -= gsl::narrow<short>(_VisibleStartIndex());

SetSelectionAnchor(realCoordStart);
SetSelectionEnd(realCoordEnd, winrt::Microsoft::Terminal::Core::SelectionExpansion::Char);
SetSelectionEnd(realCoordEnd, InternalSelectionExpansion::Char);
}

const std::wstring_view Terminal::GetConsoleTitle() const noexcept
Expand Down
Loading

0 comments on commit 95967ec

Please sign in to comment.