Skip to content

Commit 7ce3da4

Browse files
committed
Address PR feedback: mark setting as experimental and simplify enum defaults
1 parent c0b0178 commit 7ce3da4

5 files changed

Lines changed: 73 additions & 4 deletions

File tree

src/cascadia/TerminalControl/IControlSettings.idl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ namespace Microsoft.Terminal.Control
2929
MinGW,
3030
};
3131

32+
enum MiddleClickAction
33+
{
34+
Pan = 0,
35+
Paste,
36+
None,
37+
};
38+
3239
// Class Description:
3340
// TerminalSettings encapsulates all settings that control the
3441
// TermControl's behavior. In these settings there is both the entirety
@@ -77,6 +84,7 @@ namespace Microsoft.Terminal.Control
7784

7885
PathTranslationStyle PathTranslationStyle { get; };
7986
String DragDropDelimiter { get; };
87+
Microsoft.Terminal.Control.MiddleClickAction MiddleClickAction { get; };
8088

8189
// NOTE! When adding something here, make sure to update ControlProperties.h too!
8290
};

src/cascadia/TerminalControl/TermControl.cpp

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,6 +1995,15 @@ namespace winrt::Microsoft::Terminal::Control::implementation
19951995
else
19961996
{
19971997
const auto cursorPosition = point.Position();
1998+
if (point.Properties().IsMiddleButtonPressed() && !_core.IsVtMouseModeEnabled())
1999+
{
2000+
const auto action = _core.Settings().MiddleClickAction();
2001+
if (action == Control::MiddleClickAction::Pan)
2002+
{
2003+
_isPanning = true;
2004+
_panningAnchorPos = cursorPosition;
2005+
}
2006+
}
19982007
_interactivity.PointerPressed(point.PointerId(),
19992008
TermControl::GetPressedMouseButtons(point),
20002009
TermControl::GetPointerUpdateKind(point),
@@ -2019,7 +2028,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation
20192028
return;
20202029
}
20212030

2022-
RestorePointerCursor.raise(*this, nullptr);
2031+
if (!_isPanning)
2032+
{
2033+
RestorePointerCursor.raise(*this, nullptr);
2034+
}
20232035

20242036
const auto ptr = args.Pointer();
20252037
const auto point = args.GetCurrentPoint(*this);
@@ -2041,11 +2053,39 @@ namespace winrt::Microsoft::Terminal::Control::implementation
20412053
ControlKeyStates(args.KeyModifiers()),
20422054
pixelPosition);
20432055

2056+
if (_isPanning && _panningAnchorPos)
2057+
{
2058+
const auto dy = cursorPosition.Y - _panningAnchorPos->Y;
2059+
constexpr auto MinPanDist = 5.0;
2060+
2061+
if (const auto window = CoreWindow::GetForCurrentThread())
2062+
{
2063+
if (std::abs(dy) > MinPanDist)
2064+
{
2065+
window.PointerCursor(CoreCursor(CoreCursorType::SizeNorthSouth, 1));
2066+
}
2067+
else
2068+
{
2069+
window.PointerCursor(CoreCursor(CoreCursorType::SizeAll, 1));
2070+
}
2071+
}
2072+
2073+
if (std::abs(dy) > MinPanDist)
2074+
{
2075+
const auto scrollDist = dy > 0 ? (dy - MinPanDist) : (dy + MinPanDist);
2076+
const auto newVelocity = _GetAutoScrollSpeed(std::abs(scrollDist)) * (dy > 0 ? 1.0 : -1.0);
2077+
_TryStartAutoScroll(point, newVelocity);
2078+
}
2079+
else
2080+
{
2081+
_TryStopAutoScroll(ptr.PointerId());
2082+
}
2083+
}
20442084
// GH#9109 - Only start an auto-scroll when the drag actually
20452085
// started within our bounds. Otherwise, someone could start a drag
20462086
// outside the terminal control, drag into the padding, and trick us
20472087
// into starting to scroll.
2048-
if (!suppressFurtherHandling && _focused && _pointerPressedInBounds && point.Properties().IsLeftButtonPressed())
2088+
else if (!suppressFurtherHandling && _focused && _pointerPressedInBounds && point.Properties().IsLeftButtonPressed())
20492089
{
20502090
// We want to find the distance relative to the bounds of the
20512091
// SwapChainPanel, not the entire control. If they drag out of
@@ -2124,6 +2164,16 @@ namespace winrt::Microsoft::Terminal::Control::implementation
21242164
_interactivity.TouchReleased();
21252165
}
21262166

2167+
if (_isPanning)
2168+
{
2169+
_isPanning = false;
2170+
_panningAnchorPos = std::nullopt;
2171+
if (const auto window = CoreWindow::GetForCurrentThread())
2172+
{
2173+
window.PointerCursor(CoreCursor(CoreCursorType::IBeam, 1));
2174+
}
2175+
}
2176+
21272177
_TryStopAutoScroll(ptr.PointerId());
21282178

21292179
args.Handled(true);

src/cascadia/TerminalSettingsModel/MTSMSettings.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ Author(s):
111111
X(bool, AllowOscNotifications, "compatibility.allowOSC777", false) \
112112
X(bool, AllowKeypadMode, "compatibility.allowDECNKM", false) \
113113
X(hstring, DragDropDelimiter, "dragDropDelimiter", L" ") \
114-
X(Microsoft::Terminal::Control::PathTranslationStyle, PathTranslationStyle, "pathTranslationStyle", Microsoft::Terminal::Control::PathTranslationStyle::None)
114+
X(Microsoft::Terminal::Control::PathTranslationStyle, PathTranslationStyle, "pathTranslationStyle", Microsoft::Terminal::Control::PathTranslationStyle::None) \
115+
X(Microsoft::Terminal::Control::MiddleClickAction, MiddleClickAction, "experimental.middleClickAction", Microsoft::Terminal::Control::MiddleClickAction::Pan)
115116

116117
// Intentionally omitted Profile settings:
117118
// * Name

src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,15 @@ JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Control::PathTranslationStyle)
874874
};
875875
};
876876

877+
JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Control::MiddleClickAction)
878+
{
879+
static constexpr std::array<pair_type, 3> mappings = {
880+
pair_type{ "pan", ValueType::Pan },
881+
pair_type{ "paste", ValueType::Paste },
882+
pair_type{ "none", ValueType::None },
883+
};
884+
};
885+
877886
JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Control::WarnAboutMultiLinePaste)
878887
{
879888
JSON_MAPPINGS(3) = {

src/cascadia/inc/ControlProperties.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,5 @@
8989
X(winrt::Microsoft::Terminal::Control::CopyFormat, CopyFormatting, 0) \
9090
X(bool, RightClickContextMenu, false) \
9191
X(winrt::Microsoft::Terminal::Control::PathTranslationStyle, PathTranslationStyle, winrt::Microsoft::Terminal::Control::PathTranslationStyle::None) \
92-
X(winrt::hstring, DragDropDelimiter, L" ")
92+
X(winrt::hstring, DragDropDelimiter, L" ") \
93+
X(winrt::Microsoft::Terminal::Control::MiddleClickAction, MiddleClickAction, winrt::Microsoft::Terminal::Control::MiddleClickAction::Pan)

0 commit comments

Comments
 (0)