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

Add ability to select all text in the buffer #13045

Merged
2 commits merged into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,15 @@ namespace winrt::Microsoft::Terminal::Control::implementation
vkey != VK_SNAPSHOT &&
keyDown)
{
// check for "select all"
if (modifiers.IsCtrlPressed() && vkey == 'A')
carlos-zamora marked this conversation as resolved.
Show resolved Hide resolved
{
auto lock = _terminal->LockForWriting();
_terminal->SelectAll();
_renderer->TriggerSelection();
return true;
}

// try to update the selection
if (const auto updateSlnParams{ ::Terminal::ConvertKeyEventToUpdateSelectionParams(modifiers, vkey) })
{
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalCore/Terminal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ class Microsoft::Terminal::Core::Terminal final :
void SetSelectionEnd(const COORD position, std::optional<SelectionExpansion> newExpansionMode = std::nullopt);
void SetBlockSelection(const bool isEnabled) noexcept;
void UpdateSelection(SelectionDirection direction, SelectionExpansion mode);
void SelectAll();

using UpdateSelectionParams = std::optional<std::pair<SelectionDirection, SelectionExpansion>>;
static UpdateSelectionParams ConvertKeyEventToUpdateSelectionParams(const ControlKeyStates mods, const WORD vkey);
Expand Down
8 changes: 8 additions & 0 deletions src/cascadia/TerminalCore/TerminalSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,14 @@ void Terminal::UpdateSelection(SelectionDirection direction, SelectionExpansion
}
}

void Terminal::SelectAll()
{
const auto bufferSize{ _activeBuffer().GetSize() };
_selection->start = bufferSize.Origin();
_selection->end = { bufferSize.RightInclusive(), _GetMutableViewport().BottomInclusive() };
_selection->pivot = _selection->end;
}

void Terminal::_MoveByChar(SelectionDirection direction, COORD& pos)
{
switch (direction)
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/dx/DxRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1064,8 +1064,8 @@ HANDLE DxEngine::GetSwapChainHandle() noexcept
void DxEngine::_InvalidateRectangle(const til::rect& rc)
{
const auto size = _invalidMap.size();
const auto topLeft = til::point{ 0, std::min(size.height, rc.top) };
const auto bottomRight = til::point{ size.width, std::min(size.height, rc.bottom) };
const auto topLeft = til::point{ 0, std::clamp(rc.top, 0, size.height) };
const auto bottomRight = til::point{ size.width, std::clamp(rc.bottom, 0, size.height) };
_invalidMap.set(til::rect{ topLeft, bottomRight });
}

Expand Down