Added Keybindings for go up and go down page (#747)

* added keybindings

* untabfied the files

* fixed spacing issues and renamed termheight

* changed function names and other improvements

* made some auto variables const auto

* fixed tabs

* another try for the broken spacing
This commit is contained in:
Kapperchino 2019-05-15 09:21:14 -04:00 committed by Mike Griese
parent bc69d1a99a
commit 781d779b37
9 changed files with 59 additions and 8 deletions

View file

@ -323,10 +323,12 @@ namespace winrt::TerminalApp::implementation
bindings.NewTab([this]() { _OpenNewTab(std::nullopt); });
bindings.CloseTab([this]() { _CloseFocusedTab(); });
bindings.NewTabWithProfile([this](const auto index) { _OpenNewTab({ index }); });
bindings.ScrollUp([this]() { _DoScroll(-1); });
bindings.ScrollDown([this]() { _DoScroll(1); });
bindings.ScrollUp([this]() { _Scroll(-1); });
bindings.ScrollDown([this]() { _Scroll(1); });
bindings.NextTab([this]() { _SelectNextTab(true); });
bindings.PrevTab([this]() { _SelectNextTab(false); });
bindings.ScrollUpPage([this]() { _ScrollPage(-1); });
bindings.ScrollDownPage([this]() { _ScrollPage(1); });
bindings.SwitchToTab([this](const auto index) { _SelectTab({ index }); });
bindings.OpenSettings([this]() { _OpenSettings(); });
}
@ -676,12 +678,29 @@ namespace winrt::TerminalApp::implementation
// view up, and positive values will move the viewport down.
// Arguments:
// - delta: a number of lines to move the viewport relative to the current viewport.
void App::_DoScroll(int delta)
void App::_Scroll(int delta)
{
int focusedTabIndex = _GetFocusedTabIndex();
_tabs[focusedTabIndex]->Scroll(delta);
}
// Method Description:
// - Move the viewport of the terminal of the currently focused tab up or
// down a page. The page length will be dependent on the terminal view height.
// Negative values of `delta` will move the view up by one page, and positive values
// will move the viewport down by one page.
// Arguments:
// - delta: The direction to move the view relative to the current viewport(it
// is clamped between -1 and 1)
void App::_ScrollPage(int delta)
{
delta = std::clamp(delta, -1, 1);
const auto focusedTabIndex = _GetFocusedTabIndex();
const auto control = _tabs[focusedTabIndex]->GetTerminalControl();
const auto termHeight = control.GetViewHeight();
_tabs[focusedTabIndex]->Scroll(termHeight * delta);
}
// Method Description:
// - Copy text from the focused terminal to the Windows Clipboard
// Arguments:

View file

@ -95,10 +95,11 @@ namespace winrt::TerminalApp::implementation
void _SetFocusedTabIndex(int tabIndex);
int _GetFocusedTabIndex() const;
void _DoScroll(int delta);
void _Scroll(int delta);
void _CopyText(const bool trimTrailingWhitespace);
// Todo: add more event implementations here
// MSFT:20641986: Add keybindings for New Window
void _ScrollPage(int delta);
void _OnTabSelectionChanged(const IInspectable& sender, const Windows::UI::Xaml::Controls::SelectionChangedEventArgs& eventArgs);
void _OnTabClosing(const IInspectable& sender, const Microsoft::UI::Xaml::Controls::TabViewTabClosingEventArgs& eventArgs);

View file

@ -89,14 +89,18 @@ namespace winrt::TerminalApp::implementation
case ShortcutAction::ScrollDown:
_ScrollDownHandlers();
return true;
case ShortcutAction::ScrollUpPage:
_ScrollUpPageHandlers();
return true;
case ShortcutAction::ScrollDownPage:
_ScrollDownPageHandlers();
return true;
case ShortcutAction::NextTab:
_NextTabHandlers();
return true;
case ShortcutAction::PrevTab:
_PrevTabHandlers();
return true;
case ShortcutAction::SwitchToTab0:
_SwitchToTabHandlers(0);
return true;
@ -146,6 +150,8 @@ namespace winrt::TerminalApp::implementation
DEFINE_EVENT(AppKeyBindings, DecreaseFontSize, _DecreaseFontSizeHandlers, TerminalApp::DecreaseFontSizeEventArgs);
DEFINE_EVENT(AppKeyBindings, ScrollUp, _ScrollUpHandlers, TerminalApp::ScrollUpEventArgs);
DEFINE_EVENT(AppKeyBindings, ScrollDown, _ScrollDownHandlers, TerminalApp::ScrollDownEventArgs);
DEFINE_EVENT(AppKeyBindings, ScrollUpPage, _ScrollUpPageHandlers, TerminalApp::ScrollUpPageEventArgs);
DEFINE_EVENT(AppKeyBindings, ScrollDownPage, _ScrollDownPageHandlers, TerminalApp::ScrollDownPageEventArgs);
DEFINE_EVENT(AppKeyBindings, OpenSettings, _OpenSettingsHandlers, TerminalApp::OpenSettingsEventArgs);

View file

@ -49,6 +49,8 @@ namespace winrt::TerminalApp::implementation
DECLARE_EVENT(DecreaseFontSize, _DecreaseFontSizeHandlers, TerminalApp::DecreaseFontSizeEventArgs);
DECLARE_EVENT(ScrollUp, _ScrollUpHandlers, TerminalApp::ScrollUpEventArgs);
DECLARE_EVENT(ScrollDown, _ScrollDownHandlers, TerminalApp::ScrollDownEventArgs);
DECLARE_EVENT(ScrollUpPage, _ScrollUpPageHandlers, TerminalApp::ScrollUpPageEventArgs);
DECLARE_EVENT(ScrollDownPage, _ScrollDownPageHandlers, TerminalApp::ScrollDownPageEventArgs);
DECLARE_EVENT(OpenSettings, _OpenSettingsHandlers, TerminalApp::OpenSettingsEventArgs);
private:

View file

@ -37,6 +37,8 @@ namespace TerminalApp
DecreaseFontSize,
ScrollUp,
ScrollDown,
ScrollUpPage,
ScrollDownPage,
OpenSettings
};
@ -54,6 +56,8 @@ namespace TerminalApp
delegate void DecreaseFontSizeEventArgs();
delegate void ScrollUpEventArgs();
delegate void ScrollDownEventArgs();
delegate void ScrollUpPageEventArgs();
delegate void ScrollDownPageEventArgs();
delegate void OpenSettingsEventArgs();
[default_interface]
@ -77,6 +81,8 @@ namespace TerminalApp
event DecreaseFontSizeEventArgs DecreaseFontSize;
event ScrollUpEventArgs ScrollUp;
event ScrollDownEventArgs ScrollDown;
event ScrollUpPageEventArgs ScrollUpPage;
event ScrollDownPageEventArgs ScrollDownPage;
event OpenSettingsEventArgs OpenSettings;
}
}

View file

@ -284,11 +284,16 @@ void CascadiaSettings::_CreateDefaultKeybindings()
keyBindings.SetKeyBinding(ShortcutAction::ScrollUp,
KeyChord{ KeyModifiers::Ctrl | KeyModifiers::Shift,
VK_PRIOR });
VK_UP });
keyBindings.SetKeyBinding(ShortcutAction::ScrollDown,
KeyChord{ KeyModifiers::Ctrl | KeyModifiers::Shift,
VK_DOWN });
keyBindings.SetKeyBinding(ShortcutAction::ScrollDownPage,
KeyChord{ KeyModifiers::Ctrl | KeyModifiers::Shift,
VK_NEXT });
keyBindings.SetKeyBinding(ShortcutAction::ScrollUpPage,
KeyChord{ KeyModifiers::Ctrl | KeyModifiers::Shift,
VK_PRIOR });
keyBindings.SetKeyBinding(ShortcutAction::SwitchToTab0,
KeyChord{ KeyModifiers::Alt,
static_cast<int>('1') });

View file

@ -1040,6 +1040,16 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
return _terminal->GetScrollOffset();
}
// Function Description:
// - Gets the height of the terminal in lines of text
// Return Value:
// - The height of the terminal in lines of text
int TermControl::GetViewHeight() const
{
const auto viewPort = _terminal->GetViewport();
return viewPort.Height();
}
// Function Description:
// - Determines how much space (in pixels) an app would need to reserve to
// create a control with the settings stored in the settings param. This

View file

@ -44,6 +44,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
void ScrollViewport(int viewTop);
int GetScrollOffset();
int GetViewHeight() const;
void SwapChainChanged();
~TermControl();

View file

@ -36,6 +36,7 @@ namespace Microsoft.Terminal.TerminalControl
void ScrollViewport(Int32 viewTop);
Int32 GetScrollOffset();
Int32 GetViewHeight();
event ScrollPositionChangedEventArgs ScrollPositionChanged;
}
}