Add keyboard shortcuts to increase and decrease font size (#2700)
* Hook up font size key bindings and events * Combine increase and decrease font size events * Add zoom keybindings to defaults.json * Fix whitespace
This commit is contained in:
parent
1caece74ab
commit
083be43700
|
@ -11,3 +11,4 @@
|
|||
#include "SwitchToTabArgs.g.cpp"
|
||||
#include "ResizePaneArgs.g.cpp"
|
||||
#include "MoveFocusArgs.g.cpp"
|
||||
#include "AdjustFontSizeArgs.g.cpp"
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "SwitchToTabArgs.g.h"
|
||||
#include "ResizePaneArgs.g.h"
|
||||
#include "MoveFocusArgs.g.h"
|
||||
#include "AdjustFontSizeArgs.g.h"
|
||||
|
||||
#include "../../cascadia/inc/cppwinrt_utils.h"
|
||||
|
||||
|
@ -61,6 +62,11 @@ namespace winrt::TerminalApp::implementation
|
|||
GETSET_PROPERTY(TerminalApp::Direction, Direction, TerminalApp::Direction::Left);
|
||||
};
|
||||
|
||||
struct AdjustFontSizeArgs : public AdjustFontSizeArgsT<AdjustFontSizeArgs>
|
||||
{
|
||||
AdjustFontSizeArgs() = default;
|
||||
GETSET_PROPERTY(int32_t, Delta, 0);
|
||||
};
|
||||
}
|
||||
|
||||
namespace winrt::TerminalApp::factory_implementation
|
||||
|
|
|
@ -51,4 +51,8 @@ namespace TerminalApp
|
|||
Direction Direction { get; };
|
||||
};
|
||||
|
||||
[default_interface] runtimeclass AdjustFontSizeArgs : IActionArgs
|
||||
{
|
||||
Int32 Delta { get; };
|
||||
};
|
||||
}
|
||||
|
|
|
@ -188,4 +188,14 @@ namespace winrt::TerminalApp::implementation
|
|||
}
|
||||
}
|
||||
|
||||
void TerminalPage::_HandleAdjustFontSize(const IInspectable& /*sender*/,
|
||||
const TerminalApp::ActionEventArgs& args)
|
||||
{
|
||||
if (const auto& realArgs = args.ActionArgs().try_as<TerminalApp::AdjustFontSizeArgs>())
|
||||
{
|
||||
const auto termControl = _GetFocusedControl();
|
||||
termControl.AdjustFontSize(realArgs.Delta());
|
||||
args.Handled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -388,6 +388,22 @@ namespace winrt::TerminalApp::implementation
|
|||
_MoveFocusHandlers(*this, *eventArgs);
|
||||
return eventArgs->Handled();
|
||||
}
|
||||
case ShortcutAction::IncreaseFontSize:
|
||||
{
|
||||
auto args = winrt::make_self<AdjustFontSizeArgs>();
|
||||
args->Delta(1);
|
||||
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
|
||||
_AdjustFontSizeHandlers(*this, *eventArgs);
|
||||
return eventArgs->Handled();
|
||||
}
|
||||
case ShortcutAction::DecreaseFontSize:
|
||||
{
|
||||
auto args = winrt::make_self<AdjustFontSizeArgs>();
|
||||
args->Delta(-1);
|
||||
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
|
||||
_AdjustFontSizeHandlers(*this, *eventArgs);
|
||||
return eventArgs->Handled();
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -67,8 +67,7 @@ namespace winrt::TerminalApp::implementation
|
|||
TYPED_EVENT(PrevTab, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs);
|
||||
TYPED_EVENT(SplitVertical, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs);
|
||||
TYPED_EVENT(SplitHorizontal, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs);
|
||||
TYPED_EVENT(IncreaseFontSize, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs);
|
||||
TYPED_EVENT(DecreaseFontSize, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs);
|
||||
TYPED_EVENT(AdjustFontSize, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs);
|
||||
TYPED_EVENT(ScrollUp, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs);
|
||||
TYPED_EVENT(ScrollDown, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs);
|
||||
TYPED_EVENT(ScrollUpPage, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs);
|
||||
|
|
|
@ -79,8 +79,7 @@ namespace TerminalApp
|
|||
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> PrevTab;
|
||||
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> SplitVertical;
|
||||
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> SplitHorizontal;
|
||||
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> IncreaseFontSize;
|
||||
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> DecreaseFontSize;
|
||||
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> AdjustFontSize;
|
||||
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> ScrollUp;
|
||||
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> ScrollDown;
|
||||
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> ScrollUpPage;
|
||||
|
|
|
@ -552,6 +552,7 @@ namespace winrt::TerminalApp::implementation
|
|||
bindings.ResizePane({ this, &TerminalPage::_HandleResizePane });
|
||||
bindings.MoveFocus({ this, &TerminalPage::_HandleMoveFocus });
|
||||
bindings.CopyText({ this, &TerminalPage::_HandleCopyText });
|
||||
bindings.AdjustFontSize({ this, &TerminalPage::_HandleAdjustFontSize });
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
|
|
|
@ -148,6 +148,7 @@ namespace winrt::TerminalApp::implementation
|
|||
void _HandleMoveFocus(const IInspectable& sender, const TerminalApp::ActionEventArgs& args);
|
||||
void _HandleCopyText(const IInspectable& sender, const TerminalApp::ActionEventArgs& args);
|
||||
void _HandleCloseWindow(const IInspectable&, const TerminalApp::ActionEventArgs& args);
|
||||
void _HandleAdjustFontSize(const IInspectable& sender, const TerminalApp::ActionEventArgs& args);
|
||||
#pragma endregion
|
||||
};
|
||||
}
|
||||
|
|
|
@ -232,6 +232,8 @@
|
|||
{ "command": "switchToTab5", "keys": ["ctrl+alt+6"] },
|
||||
{ "command": "switchToTab6", "keys": ["ctrl+alt+7"] },
|
||||
{ "command": "switchToTab7", "keys": ["ctrl+alt+8"] },
|
||||
{ "command": "switchToTab8", "keys": ["ctrl+alt+9"] }
|
||||
{ "command": "switchToTab8", "keys": ["ctrl+alt+9"] },
|
||||
{ "command": "decreaseFontSize", "keys": ["ctrl+-"] },
|
||||
{ "command": "increaseFontSize", "keys": ["ctrl+="] }
|
||||
]
|
||||
}
|
||||
|
|
|
@ -987,10 +987,19 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
|
|||
void TermControl::_MouseZoomHandler(const double mouseDelta)
|
||||
{
|
||||
const auto fontDelta = mouseDelta < 0 ? -1 : 1;
|
||||
AdjustFontSize(fontDelta);
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
// - Adjust the font size of the terminal control.
|
||||
// Arguments:
|
||||
// - fontSizeDelta: The amount to increase or decrease the font size by.
|
||||
void TermControl::AdjustFontSize(int fontSizeDelta)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Make sure we have a non-zero font size
|
||||
const auto newSize = std::max(gsl::narrow<short>(_desiredFont.GetEngineSize().Y + fontDelta), static_cast<short>(1));
|
||||
const auto newSize = std::max(gsl::narrow<short>(_desiredFont.GetEngineSize().Y + fontSizeDelta), static_cast<short>(1));
|
||||
const auto* fontFace = _settings.FontFace().c_str();
|
||||
_actualFont = { fontFace, 0, 10, { 0, newSize }, CP_UTF8, false };
|
||||
_desiredFont = { _actualFont };
|
||||
|
|
|
@ -68,6 +68,8 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
|
|||
int GetScrollOffset();
|
||||
int GetViewHeight() const;
|
||||
|
||||
void AdjustFontSize(int fontSizeDelta);
|
||||
|
||||
void SwapChainChanged();
|
||||
~TermControl();
|
||||
|
||||
|
|
|
@ -46,5 +46,7 @@ namespace Microsoft.Terminal.TerminalControl
|
|||
Int32 GetScrollOffset();
|
||||
Int32 GetViewHeight();
|
||||
event ScrollPositionChangedEventArgs ScrollPositionChanged;
|
||||
|
||||
void AdjustFontSize(Int32 fontSizeDelta);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue