Compare commits

...

5 commits

Author SHA1 Message Date
Mike Griese ad9900857a This should fix carlos's CI build 2021-09-09 10:04:45 -05:00
Carlos Zamora 0cc9bd0aad fix schema 2021-09-02 13:55:05 -07:00
Carlos Zamora b371eed864 fix bad merge 2021-09-02 13:55:01 -07:00
Carlos Zamora 45af92d1af apply feedback from zadji 2021-09-02 13:54:02 -07:00
Carlos Zamora 5b51af1021 Implement Keyboard Selection 2021-09-02 13:51:59 -07:00
27 changed files with 461 additions and 58 deletions

View file

@ -303,6 +303,7 @@
"toggleSplitOrientation",
"toggleReadOnlyMode",
"toggleShaderEffects",
"updateSelection",
"wt",
"unbound"
],
@ -330,6 +331,24 @@
],
"type": "string"
},
"SelectionDirection": {
"enum": [
"left",
"right",
"up",
"down"
],
"type": "string"
},
"SelectionMode": {
"enum": [
"char",
"word",
"view",
"buffer"
],
"type": "string"
},
"MoveTabDirection": {
"enum": [
"forward",
@ -582,6 +601,28 @@
],
"required": [ "direction" ]
},
"UpdateSelectionAction": {
"description": "Arguments corresponding to a Update Selection Action",
"allOf": [
{ "$ref": "#/definitions/ShortcutAction" },
{
"properties": {
"action": { "type": "string", "pattern": "updateSelection" },
"direction": {
"$ref": "#/definitions/SelectionDirection",
"default": "left",
"description": "The direction to move the selection endpoint in."
},
"mode": {
"$ref": "#/definitions/SelectionMode",
"default": "cell",
"description": "The expansion mode to move the selection endpoint by."
}
}
}
],
"required": [ "direction" ]
},
"ResizePaneAction": {
"description": "Arguments corresponding to a Resize Pane Action",
"allOf": [
@ -1062,6 +1103,7 @@
{ "$ref": "#/definitions/FocusPaneAction" },
{ "$ref": "#/definitions/GlobalSummonAction" },
{ "$ref": "#/definitions/QuakeModeAction" },
{ "$ref": "#/definitions/UpdateSelectionAction" },
{ "type": "null" }
]
},

View file

@ -1414,12 +1414,13 @@ const til::point TextBuffer::GetGlyphStart(const til::point pos) const
}
// Method Description:
// - Update pos to be the end of the current glyph/character. This is used for accessibility
// - Update pos to be the end of the current glyph/character.
// Arguments:
// - pos - a COORD on the word you are currently on
// - accessibilityMode - this is being used for accessibility; make the end exclusive.
// Return Value:
// - pos - The COORD for the last cell of the current glyph (exclusive)
const til::point TextBuffer::GetGlyphEnd(const til::point pos) const
const til::point TextBuffer::GetGlyphEnd(const til::point pos, bool accessibilityMode) const
{
COORD resultPos = pos;
@ -1430,7 +1431,10 @@ const til::point TextBuffer::GetGlyphEnd(const til::point pos) const
}
// increment one more time to become exclusive
bufferSize.IncrementInBounds(resultPos, true);
if (accessibilityMode)
{
bufferSize.IncrementInBounds(resultPos, true);
}
return resultPos;
}

View file

@ -147,7 +147,7 @@ public:
bool MoveToPreviousWord(COORD& pos, const std::wstring_view wordDelimiters) const;
const til::point GetGlyphStart(const til::point pos) const;
const til::point GetGlyphEnd(const til::point pos) const;
const til::point GetGlyphEnd(const til::point pos, bool accessibilityMode = false) const;
bool MoveToNextGlyph(til::point& pos, bool allowBottomExclusive = false) const;
bool MoveToPreviousGlyph(til::point& pos) const;

View file

@ -549,11 +549,11 @@ try
if (multiClickMapper == 3)
{
_terminal->MultiClickSelection(cursorPosition / fontSize, ::Terminal::SelectionExpansionMode::Line);
_terminal->MultiClickSelection(cursorPosition / fontSize, winrt::Microsoft::Terminal::Core::SelectionExpansion::Line);
}
else if (multiClickMapper == 2)
{
_terminal->MultiClickSelection(cursorPosition / fontSize, ::Terminal::SelectionExpansionMode::Word);
_terminal->MultiClickSelection(cursorPosition / fontSize, winrt::Microsoft::Terminal::Core::SelectionExpansion::Word);
}
else
{

View file

@ -44,6 +44,13 @@
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>$(SolutionDir)src\cascadia\TerminalCore\lib\Generated Files\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
<Import Project="$(SolutionDir)src\common.build.post.props" />
<!-- LATE LINK LINE OVERRIDES. This project must link named forwarders

View file

@ -9,3 +9,5 @@
#endif
#include <LibraryIncludes.h>
#define CPPWINRT_VERSION "2.0.210309.3"
#include "winrt/Microsoft.Terminal.Core.h"

View file

@ -907,4 +907,19 @@ namespace winrt::TerminalApp::implementation
}
}
}
void TerminalPage::_HandleUpdateSelection(const IInspectable& /*sender*/,
const ActionEventArgs& args)
{
if (args)
{
if (const auto& realArgs = args.ActionArgs().try_as<UpdateSelectionArgs>())
{
if (const auto termControl{ _GetActiveControl() })
{
args.Handled(termControl.UpdateSelection(realArgs.Direction(), realArgs.Mode()));
}
}
}
}
}

View file

@ -927,6 +927,21 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_renderer->TriggerSelection();
}
bool ControlCore::UpdateSelection(Core::SelectionDirection direction, Core::SelectionExpansion mode)
{
// - SelectionDirection cannot be none
// - A selection must be active for us to update it
if (direction == Core::SelectionDirection::None || !HasSelection())
{
return false;
}
auto lock = _terminal->LockForWriting();
_terminal->UpdateSelection(direction, mode);
_renderer->TriggerSelection();
return true;
}
// Called when the Terminal wants to set something to the clipboard, i.e.
// when an OSC 52 is emitted.
void ControlCore::_terminalCopyToClipboard(std::wstring_view wstr)
@ -1422,18 +1437,18 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// handle ALT key
_terminal->SetBlockSelection(altEnabled);
::Terminal::SelectionExpansionMode mode = ::Terminal::SelectionExpansionMode::Cell;
Core::SelectionExpansion mode = Core::SelectionExpansion::Char;
if (numberOfClicks == 1)
{
mode = ::Terminal::SelectionExpansionMode::Cell;
mode = Core::SelectionExpansion::Char;
}
else if (numberOfClicks == 2)
{
mode = ::Terminal::SelectionExpansionMode::Word;
mode = Core::SelectionExpansion::Word;
}
else if (numberOfClicks == 3)
{
mode = ::Terminal::SelectionExpansionMode::Line;
mode = Core::SelectionExpansion::Line;
}
// Update the selection appropriately
@ -1458,7 +1473,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_terminal->SetSelectionEnd(terminalPosition, mode);
selectionNeedsToBeCopied = true;
}
else if (mode != ::Terminal::SelectionExpansionMode::Cell || shiftEnabled)
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

View file

@ -130,6 +130,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
Windows::Foundation::Collections::IVector<winrt::hstring> SelectedText(bool trimTrailingWhitespace) const;
void SetSelectionAnchor(til::point const& position);
void SetEndSelectionPoint(til::point const& position);
bool UpdateSelection(Core::SelectionDirection direction, Core::SelectionExpansion mode);
void Search(const winrt::hstring& text,
const bool goForward,

View file

@ -80,6 +80,7 @@ namespace Microsoft.Terminal.Control
Boolean HasSelection { get; };
IVector<String> SelectedText(Boolean trimTrailingWhitespace);
Boolean UpdateSelection(Microsoft.Terminal.Core.SelectionDirection direction, Microsoft.Terminal.Core.SelectionExpansion mode);
String HoveredUriText { get; };
Windows.Foundation.IReference<Microsoft.Terminal.Core.Point> HoveredCell { get; };

View file

@ -2595,4 +2595,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
return _core.ReadEntireBuffer();
}
bool TermControl::UpdateSelection(Core::SelectionDirection direction, Core::SelectionExpansion mode)
{
return _core.UpdateSelection(direction, mode);
}
}

View file

@ -32,6 +32,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
hstring GetProfileName() const;
bool UpdateSelection(Core::SelectionDirection direction, Core::SelectionExpansion mode);
bool CopySelectionToClipboard(bool singleLine, const Windows::Foundation::IReference<CopyFormat>& formats);
void PasteTextFromClipboard();
void Close();

View file

@ -45,6 +45,7 @@ namespace Microsoft.Terminal.Control
// We expose this and ConnectionState here so that it might eventually be data bound.
event Windows.Foundation.TypedEventHandler<Object, IInspectable> ConnectionStateChanged;
Boolean UpdateSelection(Microsoft.Terminal.Core.SelectionDirection direction, Microsoft.Terminal.Core.SelectionExpansion mode);
Boolean CopySelectionToClipboard(Boolean singleLine, Windows.Foundation.IReference<CopyFormat> formats);
void PasteTextFromClipboard();
void ClearBuffer(ClearBufferType clearType);

View file

@ -5,6 +5,24 @@ import "..\ICoreAppearance.idl";
namespace Microsoft.Terminal.Core
{
enum SelectionDirection
{
None = 0,
Left,
Right,
Up,
Down,
};
enum SelectionExpansion
{
Char,
Word,
Line, // Mouse selection only! Not a setting!
Viewport,
Buffer
};
interface ICoreSettings requires ICoreAppearance
{
// TODO:MSFT:20642297 - define a sentinel for Infinite Scrollback

View file

@ -227,16 +227,11 @@ public:
#pragma region TextSelection
// These methods are defined in TerminalSelection.cpp
enum class SelectionExpansionMode
{
Cell,
Word,
Line
};
void MultiClickSelection(const COORD viewportPos, SelectionExpansionMode expansionMode);
void MultiClickSelection(const COORD viewportPos, winrt::Microsoft::Terminal::Core::SelectionExpansion expansionMode);
void SetSelectionAnchor(const COORD position);
void SetSelectionEnd(const COORD position, std::optional<SelectionExpansionMode> newExpansionMode = std::nullopt);
void SetSelectionEnd(const COORD position, std::optional<winrt::Microsoft::Terminal::Core::SelectionExpansion> newExpansionMode = std::nullopt);
void SetBlockSelection(const bool isEnabled) noexcept;
void UpdateSelection(winrt::Microsoft::Terminal::Core::SelectionDirection direction, winrt::Microsoft::Terminal::Core::SelectionExpansion mode);
const TextBuffer::TextAndColor RetrieveSelectedTextFromBuffer(bool trimTrailingWhitespace);
#pragma endregion
@ -308,7 +303,7 @@ private:
std::optional<SelectionAnchors> _selection;
bool _blockSelection;
std::wstring _wordDelimiters;
SelectionExpansionMode _multiClickSelectionMode;
winrt::Microsoft::Terminal::Core::SelectionExpansion _multiClickSelectionMode;
#pragma endregion
// TODO: These members are not shared by an alt-buffer. They should be
@ -372,9 +367,13 @@ private:
#pragma region TextSelection
// These methods are defined in TerminalSelection.cpp
std::vector<SMALL_RECT> _GetSelectionRects() const noexcept;
std::pair<COORD, COORD> _PivotSelection(const COORD targetPos, bool& targetStart) const;
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);
#pragma endregion
Microsoft::Console::VirtualTerminal::SgrStack _sgrStack;

View file

@ -5,7 +5,10 @@
#include "Terminal.hpp"
#include "unicode.hpp"
#include <winrt/Microsoft.Terminal.Core.h>
using namespace Microsoft::Terminal::Core;
using namespace winrt::Microsoft::Terminal::Core;
/* Selection Pivot Description:
* The pivot helps properly update the selection when a user moves a selection over itself
@ -100,8 +103,8 @@ const bool Terminal::IsBlockSelection() const noexcept
// - Perform a multi-click selection at viewportPos expanding according to the expansionMode
// Arguments:
// - viewportPos: the (x,y) coordinate on the visible viewport
// - expansionMode: the SelectionExpansionMode to dictate the boundaries of the selection anchors
void Terminal::MultiClickSelection(const COORD viewportPos, SelectionExpansionMode expansionMode)
// - expansionMode: the SelectionExpansion to dictate the boundaries of the selection anchors
void Terminal::MultiClickSelection(const COORD viewportPos, SelectionExpansion expansionMode)
{
// set the selection pivot to expand the selection using SetSelectionEnd()
_selection = SelectionAnchors{};
@ -124,7 +127,7 @@ void Terminal::SetSelectionAnchor(const COORD viewportPos)
_selection = SelectionAnchors{};
_selection->pivot = _ConvertToBufferCell(viewportPos);
_multiClickSelectionMode = SelectionExpansionMode::Cell;
_multiClickSelectionMode = SelectionExpansion::Char;
SetSelectionEnd(viewportPos);
_selection->start = _selection->pivot;
@ -136,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<SelectionExpansionMode> newExpansionMode)
void Terminal::SetSelectionEnd(const COORD viewportPos, std::optional<SelectionExpansion> newExpansionMode)
{
if (!_selection.has_value())
{
@ -151,8 +154,9 @@ void Terminal::SetSelectionEnd(const COORD viewportPos, std::optional<SelectionE
// Otherwise, we may accidentally expand during other selection-based actions
_multiClickSelectionMode = newExpansionMode.has_value() ? *newExpansionMode : _multiClickSelectionMode;
bool targetStart = false;
const auto anchors = _PivotSelection(textBufferPos, targetStart);
std::pair<COORD, COORD> anchors;
bool targetStart;
std::tie(anchors.first, anchors.second, targetStart) = _PivotSelection(textBufferPos);
const auto expandedAnchors = _ExpandSelectionAnchors(anchors);
if (newExpansionMode.has_value())
@ -177,22 +181,24 @@ void Terminal::SetSelectionEnd(const COORD viewportPos, std::optional<SelectionE
// - This ensures start < end when compared
// Arguments:
// - targetPos: the (x,y) coordinate we are moving to on the text buffer
// - targetStart: if true, target will be the new start. Otherwise, target will be the new end.
// Return Value:
// - the new start/end for a selection
std::pair<COORD, COORD> Terminal::_PivotSelection(const COORD targetPos, bool& targetStart) const
// - COORD: the new start for a selection
// - COORD: the new end for a selection
// - bool: if true, target will be the new start. Otherwise, target will be the new end.
std::tuple<COORD, COORD, bool> Terminal::_PivotSelection(const COORD targetPos) const
{
if (targetStart = _buffer->GetSize().CompareInBounds(targetPos, _selection->pivot) <= 0)
const bool targetStart{ _buffer->GetSize().CompareInBounds(targetPos, _selection->pivot) <= 0 };
if (targetStart)
{
// target is before pivot
// treat target as start
return std::make_pair(targetPos, _selection->pivot);
return { targetPos, _selection->pivot, targetStart };
}
else
{
// target is after pivot
// treat pivot as start
return std::make_pair(_selection->pivot, targetPos);
return { _selection->pivot, targetPos, targetStart };
}
}
@ -210,15 +216,15 @@ std::pair<COORD, COORD> Terminal::_ExpandSelectionAnchors(std::pair<COORD, COORD
const auto bufferSize = _buffer->GetSize();
switch (_multiClickSelectionMode)
{
case SelectionExpansionMode::Line:
case SelectionExpansion::Line:
start = { bufferSize.Left(), start.Y };
end = { bufferSize.RightInclusive(), end.Y };
break;
case SelectionExpansionMode::Word:
case SelectionExpansion::Word:
start = _buffer->GetWordStart(start, _wordDelimiters);
end = _buffer->GetWordEnd(end, _wordDelimiters);
break;
case SelectionExpansionMode::Cell:
case SelectionExpansion::Char:
default:
// no expansion is necessary
break;
@ -235,6 +241,181 @@ void Terminal::SetBlockSelection(const bool isEnabled) noexcept
_blockSelection = isEnabled;
}
void Terminal::UpdateSelection(SelectionDirection direction, SelectionExpansion 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.
const bool movingEnd{ _selection->start == _selection->pivot };
auto targetPos{ movingEnd ? _selection->end : _selection->start };
// 2. Perform the movement
switch (mode)
{
case SelectionExpansion::Char:
_MoveByChar(direction, targetPos);
break;
case SelectionExpansion::Word:
_MoveByWord(direction, targetPos);
break;
case SelectionExpansion::Viewport:
_MoveByViewport(direction, targetPos);
break;
case SelectionExpansion::Buffer:
_MoveByBuffer(direction, targetPos);
break;
}
// 3. Actually modify the selection
std::tie(_selection->start, _selection->end, std::ignore) = _PivotSelection(targetPos);
// 4. Scroll (if necessary)
if (const auto viewport = _GetVisibleViewport(); !viewport.IsInBounds(targetPos))
{
if (const auto amtAboveView = viewport.Top() - targetPos.Y; amtAboveView > 0)
{
// anchor is above visible viewport, scroll by that amount
_scrollOffset += amtAboveView;
}
else
{
// anchor is below visible viewport, scroll by that amount
const auto amtBelowView = targetPos.Y - viewport.BottomInclusive();
_scrollOffset -= amtBelowView;
}
_NotifyScrollEvent();
_buffer->GetRenderTarget().TriggerScroll();
}
}
void Terminal::_MoveByChar(SelectionDirection direction, COORD& pos)
{
switch (direction)
{
case SelectionDirection::Left:
_buffer->GetSize().DecrementInBounds(pos);
pos = _buffer->GetGlyphStart(pos);
break;
case SelectionDirection::Right:
_buffer->GetSize().IncrementInBounds(pos);
pos = _buffer->GetGlyphEnd(pos);
break;
case SelectionDirection::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:
{
const auto bufferSize{ _buffer->GetSize() };
pos = { pos.X, std::clamp(base::ClampAdd<short, short>(pos.Y, 1).RawValue(), bufferSize.Top(), bufferSize.BottomInclusive()) };
break;
}
}
}
void Terminal::_MoveByWord(SelectionDirection direction, COORD& pos)
{
switch (direction)
{
case SelectionDirection::Left:
const auto wordStartPos{ _buffer->GetWordStart(pos, _wordDelimiters) };
if (_buffer->GetSize().CompareInBounds(_selection->pivot, pos) < 0)
{
// If we're moving towards the pivot, move one more cell
pos = wordStartPos;
_buffer->GetSize().DecrementInBounds(pos);
}
else if (wordStartPos == pos)
{
// already at the beginning of the current word,
// move to the beginning of the previous word
_buffer->GetSize().DecrementInBounds(pos);
pos = _buffer->GetWordStart(pos, _wordDelimiters);
}
else
{
// move to the beginning of the current word
pos = wordStartPos;
}
break;
case SelectionDirection::Right:
const auto wordEndPos{ _buffer->GetWordEnd(pos, _wordDelimiters) };
if (_buffer->GetSize().CompareInBounds(pos, _selection->pivot) < 0)
{
// If we're moving towards the pivot, move one more cell
pos = _buffer->GetWordEnd(pos, _wordDelimiters);
_buffer->GetSize().IncrementInBounds(pos);
}
else if (wordEndPos == pos)
{
// already at the end of the current word,
// move to the end of the next word
_buffer->GetSize().IncrementInBounds(pos);
pos = _buffer->GetWordEnd(pos, _wordDelimiters);
}
else
{
// move to the end of the current word
pos = wordEndPos;
}
break;
case SelectionDirection::Up:
_MoveByChar(direction, pos);
pos = _buffer->GetWordStart(pos, _wordDelimiters);
break;
case SelectionDirection::Down:
_MoveByChar(direction, pos);
pos = _buffer->GetWordEnd(pos, _wordDelimiters);
break;
}
}
void Terminal::_MoveByViewport(SelectionDirection direction, COORD& pos)
{
const auto bufferSize{ _buffer->GetSize() };
switch (direction)
{
case SelectionDirection::Left:
pos = { bufferSize.Left(), pos.Y };
break;
case SelectionDirection::Right:
pos = { bufferSize.RightInclusive(), pos.Y };
break;
case SelectionDirection::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:
{
const auto viewportHeight{ _mutableViewport.Height() };
const auto mutableBottom{ _mutableViewport.BottomInclusive() };
const auto newY{ base::ClampAdd<short, short>(pos.Y, viewportHeight) };
pos = newY > mutableBottom ? COORD{ bufferSize.RightInclusive(), mutableBottom } : COORD{ pos.X, newY };
break;
}
}
}
void Terminal::_MoveByBuffer(SelectionDirection direction, COORD& pos)
{
const auto bufferSize{ _buffer->GetSize() };
switch (direction)
{
case SelectionDirection::Left:
case SelectionDirection::Up:
pos = bufferSize.Origin();
break;
case SelectionDirection::Right:
case SelectionDirection::Down:
pos = { bufferSize.RightInclusive(), _mutableViewport.BottomInclusive() };
break;
}
}
// Method Description:
// - clear selection data and disable rendering it
#pragma warning(disable : 26440) // changing this to noexcept would require a change to ConHost's selection model

View file

@ -206,7 +206,7 @@ void Terminal::SelectNewRegion(const COORD coordStart, const COORD coordEnd)
realCoordEnd.Y -= gsl::narrow<short>(_VisibleStartIndex());
SetSelectionAnchor(realCoordStart);
SetSelectionEnd(realCoordEnd, SelectionExpansionMode::Cell);
SetSelectionEnd(realCoordEnd, winrt::Microsoft::Terminal::Core::SelectionExpansion::Char);
}
const std::wstring_view Terminal::GetConsoleTitle() const noexcept

View file

@ -67,6 +67,7 @@ static constexpr std::string_view QuakeModeKey{ "quakeMode" };
static constexpr std::string_view FocusPaneKey{ "focusPane" };
static constexpr std::string_view ClearBufferKey{ "clearBuffer" };
static constexpr std::string_view MultipleActionsKey{ "multipleActions" };
static constexpr std::string_view UpdateSelectionKey{ "updateSelection" };
static constexpr std::string_view ActionKey{ "action" };

View file

@ -36,6 +36,7 @@
#include "FocusPaneArgs.g.cpp"
#include "ClearBufferArgs.g.cpp"
#include "MultipleActionsArgs.g.cpp"
#include "UpdateSelectionArgs.g.cpp"
#include <LibraryResources.h>
@ -712,4 +713,9 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{
return L"";
}
winrt::hstring UpdateSelectionArgs::GenerateName() const
{
return L"";
}
}

View file

@ -38,6 +38,7 @@
#include "FocusPaneArgs.g.h"
#include "ClearBufferArgs.g.h"
#include "MultipleActionsArgs.g.h"
#include "UpdateSelectionArgs.g.h"
#include "../../cascadia/inc/cppwinrt_utils.h"
#include "JsonUtils.h"
@ -1854,6 +1855,67 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
return ::Microsoft::Terminal::Settings::Model::HashUtils::HashProperty(_Actions);
}
};
struct UpdateSelectionArgs : public UpdateSelectionArgsT<UpdateSelectionArgs>
{
UpdateSelectionArgs() = default;
ACTION_ARG(Core::SelectionDirection, Direction, Core::SelectionDirection::None);
ACTION_ARG(Core::SelectionExpansion, Mode, Core::SelectionExpansion::Char);
static constexpr std::string_view DirectionKey{ "direction" };
static constexpr std::string_view ModeKey{ "mode" };
public:
hstring GenerateName() const;
bool Equals(const IActionArgs& other)
{
auto otherAsUs = other.try_as<UpdateSelectionArgs>();
if (otherAsUs)
{
return otherAsUs->_Direction == _Direction && otherAsUs->_Mode == _Mode;
}
return false;
};
static FromJsonResult FromJson(const Json::Value& json)
{
// LOAD BEARING: Not using make_self here _will_ break you in the future!
auto args = winrt::make_self<UpdateSelectionArgs>();
JsonUtils::GetValueForKey(json, DirectionKey, args->_Direction);
JsonUtils::GetValueForKey(json, ModeKey, args->_Mode);
if (args->Direction() == Core::SelectionDirection::None)
{
return { nullptr, { SettingsLoadWarnings::MissingRequiredParameter } };
}
else
{
return { *args, {} };
}
}
static Json::Value ToJson(const IActionArgs& val)
{
if (!val)
{
return {};
}
Json::Value json{ Json::ValueType::objectValue };
const auto args{ get_self<UpdateSelectionArgs>(val) };
JsonUtils::SetValueForKey(json, DirectionKey, args->_Direction);
JsonUtils::SetValueForKey(json, ModeKey, args->_Mode);
return json;
}
IActionArgs Copy() const
{
auto copy{ winrt::make_self<UpdateSelectionArgs>() };
copy->_Direction = _Direction;
copy->_Mode = _Mode;
return *copy;
}
size_t Hash() const
{
return ::Microsoft::Terminal::Settings::Model::HashUtils::HashProperty(_Direction, _Mode);
}
};
}
namespace winrt::Microsoft::Terminal::Settings::Model::factory_implementation

View file

@ -322,4 +322,10 @@ namespace Microsoft.Terminal.Settings.Model
MultipleActionsArgs();
Windows.Foundation.Collections.IVector<ActionAndArgs> Actions;
};
[default_interface] runtimeclass UpdateSelectionArgs : IActionArgs
{
Microsoft.Terminal.Core.SelectionDirection Direction { get; };
Microsoft.Terminal.Core.SelectionExpansion Mode { get; };
};
}

View file

@ -80,7 +80,8 @@
ON_ALL_ACTIONS(QuakeMode) \
ON_ALL_ACTIONS(FocusPane) \
ON_ALL_ACTIONS(ClearBuffer) \
ON_ALL_ACTIONS(MultipleActions)
ON_ALL_ACTIONS(MultipleActions) \
ON_ALL_ACTIONS(UpdateSelection)
#define ALL_SHORTCUT_ACTIONS_WITH_ARGS \
ON_ALL_ACTIONS_WITH_ARGS(AdjustFontSize) \
@ -113,4 +114,5 @@
ON_ALL_ACTIONS_WITH_ARGS(ToggleCommandPalette) \
ON_ALL_ACTIONS_WITH_ARGS(FocusPane) \
ON_ALL_ACTIONS_WITH_ARGS(ClearBuffer) \
ON_ALL_ACTIONS_WITH_ARGS(MultipleActions)
ON_ALL_ACTIONS_WITH_ARGS(MultipleActions) \
ON_ALL_ACTIONS_WITH_ARGS(UpdateSelection)

View file

@ -491,3 +491,23 @@ JSON_FLAG_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::IntenseStyle)
};
};
JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Core::SelectionDirection)
{
static constexpr std::array<pair_type, 4> mappings = {
pair_type{ "left", ValueType::Left },
pair_type{ "right", ValueType::Right },
pair_type{ "up", ValueType::Up },
pair_type{ "down", ValueType::Down }
};
};
JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Core::SelectionExpansion)
{
static constexpr std::array<pair_type, 4> mappings = {
pair_type{ "char", ValueType::Char },
pair_type{ "word", ValueType::Word },
pair_type{ "view", ValueType::Viewport },
pair_type{ "buffer", ValueType::Buffer }
};
};

View file

@ -376,6 +376,20 @@
{ "command": "paste", "keys": "ctrl+shift+v" },
{ "command": "paste", "keys": "shift+insert" },
// Keyboard Selection
{ "command": {"action": "updateSelection", "direction": "left", "mode": "char" }, "keys": "shift+left" },
{ "command": {"action": "updateSelection", "direction": "right", "mode": "char" }, "keys": "shift+right" },
{ "command": {"action": "updateSelection", "direction": "up", "mode": "char" }, "keys": "shift+up" },
{ "command": {"action": "updateSelection", "direction": "down", "mode": "char" }, "keys": "shift+down" },
{ "command": {"action": "updateSelection", "direction": "left", "mode": "word" }, "keys": "ctrl+shift+left" },
{ "command": {"action": "updateSelection", "direction": "right", "mode": "word" }, "keys": "ctrl+shift+right" },
{ "command": {"action": "updateSelection", "direction": "left", "mode": "view" }, "keys": "shift+home" },
{ "command": {"action": "updateSelection", "direction": "right", "mode": "view" }, "keys": "shift+end" },
{ "command": {"action": "updateSelection", "direction": "up", "mode": "view" }, "keys": "shift+pgup" },
{ "command": {"action": "updateSelection", "direction": "down", "mode": "view" }, "keys": "shift+pgdn" },
{ "command": {"action": "updateSelection", "direction": "up", "mode": "buffer" }, "keys": "ctrl+shift+home" },
{ "command": {"action": "updateSelection", "direction": "down", "mode": "buffer" }, "keys": "ctrl+shift+end" },
// Scrollback
{ "command": "scrollDown", "keys": "ctrl+shift+down" },
{ "command": "scrollDownPage", "keys": "ctrl+shift+pgdn" },

View file

@ -130,7 +130,7 @@ namespace TerminalCoreUnitTests
DummyRenderTarget emptyRT;
term.Create({ 10, 10 }, scrollback, emptyRT);
term.MultiClickSelection(maxCoord, Terminal::SelectionExpansionMode::Word);
term.MultiClickSelection(maxCoord, SelectionExpansion::Word);
ValidateSingleRowSelection(term, expected);
};
@ -142,7 +142,7 @@ namespace TerminalCoreUnitTests
DummyRenderTarget emptyRT;
term.Create({ 10, 10 }, scrollback, emptyRT);
term.MultiClickSelection(maxCoord, Terminal::SelectionExpansionMode::Line);
term.MultiClickSelection(maxCoord, SelectionExpansion::Line);
ValidateSingleRowSelection(term, expected);
};
@ -501,7 +501,7 @@ namespace TerminalCoreUnitTests
// Simulate double click at (x,y) = (5,10)
auto clickPos = COORD{ 5, 10 };
term.MultiClickSelection(clickPos, Terminal::SelectionExpansionMode::Word);
term.MultiClickSelection(clickPos, SelectionExpansion::Word);
// Validate selection area
ValidateSingleRowSelection(term, SMALL_RECT({ 4, 10, (4 + gsl::narrow<SHORT>(text.size()) - 1), 10 }));
@ -519,7 +519,7 @@ namespace TerminalCoreUnitTests
// Simulate click at (x,y) = (5,10)
auto clickPos = COORD{ 5, 10 };
term.MultiClickSelection(clickPos, Terminal::SelectionExpansionMode::Word);
term.MultiClickSelection(clickPos, SelectionExpansion::Word);
// Simulate renderer calling TriggerSelection and acquiring selection area
auto selectionRects = term.GetSelectionRects();
@ -546,7 +546,7 @@ namespace TerminalCoreUnitTests
// Simulate click at (x,y) = (15,10)
// this is over the '>' char
auto clickPos = COORD{ 15, 10 };
term.MultiClickSelection(clickPos, Terminal::SelectionExpansionMode::Word);
term.MultiClickSelection(clickPos, SelectionExpansion::Word);
// ---Validate selection area---
// "Terminal" is in class 2
@ -572,7 +572,7 @@ namespace TerminalCoreUnitTests
term.Write(text);
// Simulate double click at (x,y) = (5,10)
term.MultiClickSelection({ 5, 10 }, Terminal::SelectionExpansionMode::Word);
term.MultiClickSelection({ 5, 10 }, SelectionExpansion::Word);
// Simulate move to (x,y) = (21,10)
//
@ -601,7 +601,7 @@ namespace TerminalCoreUnitTests
term.Write(text);
// Simulate double click at (x,y) = (21,10)
term.MultiClickSelection({ 21, 10 }, Terminal::SelectionExpansionMode::Word);
term.MultiClickSelection({ 21, 10 }, SelectionExpansion::Word);
// Simulate move to (x,y) = (5,10)
//
@ -622,7 +622,7 @@ namespace TerminalCoreUnitTests
// Simulate click at (x,y) = (5,10)
auto clickPos = COORD{ 5, 10 };
term.MultiClickSelection(clickPos, Terminal::SelectionExpansionMode::Line);
term.MultiClickSelection(clickPos, SelectionExpansion::Line);
// Validate selection area
ValidateSingleRowSelection(term, SMALL_RECT({ 0, 10, 99, 10 }));
@ -636,7 +636,7 @@ namespace TerminalCoreUnitTests
// Simulate click at (x,y) = (5,10)
auto clickPos = COORD{ 5, 10 };
term.MultiClickSelection(clickPos, Terminal::SelectionExpansionMode::Line);
term.MultiClickSelection(clickPos, SelectionExpansion::Line);
// Simulate move to (x,y) = (7,10)
term.SetSelectionEnd({ 7, 10 });
@ -653,7 +653,7 @@ namespace TerminalCoreUnitTests
// Simulate click at (x,y) = (5,10)
auto clickPos = COORD{ 5, 10 };
term.MultiClickSelection(clickPos, Terminal::SelectionExpansionMode::Line);
term.MultiClickSelection(clickPos, SelectionExpansion::Line);
// Simulate move to (x,y) = (5,11)
term.SetSelectionEnd({ 5, 11 });
@ -691,7 +691,7 @@ namespace TerminalCoreUnitTests
// Step 1: Create a selection on "doubleClickMe"
{
// Simulate double click at (x,y) = (5,10)
term.MultiClickSelection({ 5, 10 }, Terminal::SelectionExpansionMode::Word);
term.MultiClickSelection({ 5, 10 }, SelectionExpansion::Word);
// Validate selection area: "doubleClickMe" selected
ValidateSingleRowSelection(term, SMALL_RECT({ 4, 10, 16, 10 }));
@ -704,7 +704,7 @@ namespace TerminalCoreUnitTests
// buffer: doubleClickMe dragThroughHere
// ^ ^
// start finish
term.SetSelectionEnd({ 21, 10 }, ::Terminal::SelectionExpansionMode::Cell);
term.SetSelectionEnd({ 21, 10 }, SelectionExpansion::Char);
// Validate selection area: "doubleClickMe drag" selected
ValidateSingleRowSelection(term, SMALL_RECT({ 4, 10, 21, 10 }));
@ -717,7 +717,7 @@ namespace TerminalCoreUnitTests
// buffer: doubleClickMe dragThroughHere
// ^ ^ ^
// start click finish
term.SetSelectionEnd({ 21, 10 }, ::Terminal::SelectionExpansionMode::Word);
term.SetSelectionEnd({ 21, 10 }, SelectionExpansion::Word);
// Validate selection area: "doubleClickMe dragThroughHere" selected
ValidateSingleRowSelection(term, SMALL_RECT({ 4, 10, 32, 10 }));
@ -730,7 +730,7 @@ namespace TerminalCoreUnitTests
// buffer: doubleClickMe dragThroughHere |
// ^ ^ ^
// start click finish (boundary)
term.SetSelectionEnd({ 21, 10 }, ::Terminal::SelectionExpansionMode::Line);
term.SetSelectionEnd({ 21, 10 }, SelectionExpansion::Line);
// Validate selection area: "doubleClickMe dragThroughHere..." selected
ValidateSingleRowSelection(term, SMALL_RECT({ 4, 10, 99, 10 }));
@ -743,7 +743,7 @@ namespace TerminalCoreUnitTests
// buffer: doubleClickMe dragThroughHere
// ^ ^ ^
// start click finish
term.SetSelectionEnd({ 21, 10 }, ::Terminal::SelectionExpansionMode::Word);
term.SetSelectionEnd({ 21, 10 }, SelectionExpansion::Word);
// Validate selection area: "doubleClickMe dragThroughHere" selected
ValidateSingleRowSelection(term, SMALL_RECT({ 4, 10, 32, 10 }));
@ -825,7 +825,7 @@ namespace TerminalCoreUnitTests
// Step 4: Shift+Click at (5,10)
{
term.SetSelectionEnd({ 5, 10 }, ::Terminal::SelectionExpansionMode::Cell);
term.SetSelectionEnd({ 5, 10 }, SelectionExpansion::Char);
// Validate selection area
// NOTE: Pivot should still be (10, 10)
@ -834,7 +834,7 @@ namespace TerminalCoreUnitTests
// Step 5: Shift+Click back at (20,10)
{
term.SetSelectionEnd({ 20, 10 }, ::Terminal::SelectionExpansionMode::Cell);
term.SetSelectionEnd({ 20, 10 }, SelectionExpansion::Char);
// Validate selection area
// NOTE: Pivot should still be (10, 10)

View file

@ -2253,7 +2253,7 @@ void TextBufferTests::GetGlyphBoundaries()
_buffer->Write(iter, target);
auto start = _buffer->GetGlyphStart(target);
auto end = _buffer->GetGlyphEnd(target);
auto end = _buffer->GetGlyphEnd(target, true);
VERIFY_ARE_EQUAL(test.start, start);
VERIFY_ARE_EQUAL(wideGlyph ? test.wideGlyphEnd : test.normalEnd, end);

View file

@ -286,7 +286,7 @@ void UiaTextRangeBase::_expandToEnclosingUnit(TextUnit unit)
if (unit == TextUnit_Character)
{
_start = buffer.GetGlyphStart(_start);
_end = buffer.GetGlyphEnd(_start);
_end = buffer.GetGlyphEnd(_start, true);
}
else if (unit <= TextUnit_Word)
{