-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Enable PgUp/PgDown and Home/End in the command palette #7835
Changes from 2 commits
93979d7
bfb3eea
bdbeb88
d1a8f14
357281b
7f92f5f
93945f6
dbb4e23
6fcc5c3
4382302
6590132
d142e5e
4afd672
84a5c9d
d289053
b085799
b7687b5
a30b997
23ae653
2a82844
de2d629
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,18 +101,21 @@ namespace winrt::TerminalApp::implementation | |
// - Moves the focus up or down the list of commands. If we're at the top, | ||
// we'll loop around to the bottom, and vice-versa. | ||
// Arguments: | ||
// - moveDown: if true, we're attempting to move to the next item in the | ||
// list. Otherwise, we're attempting to move to the previous. | ||
// - moveDown: if true, we're attempting to move to the next or a few next item in the | ||
// list. Otherwise, we're attempting to move to the previous or not very many previous. | ||
// Return Value: | ||
// - <none> | ||
void CommandPalette::SelectNextItem(const bool moveDown) | ||
void CommandPalette::SelectNextItem(const bool moveDown, const bool pageButtonPressed) | ||
{ | ||
const auto listHeight = ::base::saturated_cast<int>(_filteredActionsView().ActualHeight()); | ||
const int numVisibleItems = listHeight / 42; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If 42 cannot be computed, consider extracting it to a const and documenting why this value was chosen |
||
|
||
const auto selected = _filteredActionsView().SelectedIndex(); | ||
const int numItems = ::base::saturated_cast<int>(_filteredActionsView().Items().Size()); | ||
// Wraparound math. By adding numItems and then calculating modulo numItems, | ||
// we clamp the values to the range [0, numItems) while still supporting moving | ||
// upward from 0 to numItems - 1. | ||
const auto newIndex = ((numItems + selected + (moveDown ? 1 : -1)) % numItems); | ||
const auto newIndex = ((numItems + selected + (moveDown ? (pageButtonPressed ? numVisibleItems : 1) : (pageButtonPressed ? -numVisibleItems : -1))) % numItems); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic duplication can be avoided by extracting a "delta" variable: moveDown? delta : -delta |
||
_filteredActionsView().SelectedIndex(newIndex); | ||
_filteredActionsView().ScrollIntoView(_filteredActionsView().SelectedItem()); | ||
} | ||
|
@@ -134,12 +137,12 @@ namespace winrt::TerminalApp::implementation | |
auto const state = CoreWindow::GetForCurrentThread().GetKeyState(winrt::Windows::System::VirtualKey::Shift); | ||
if (WI_IsFlagSet(state, CoreVirtualKeyStates::Down)) | ||
{ | ||
SelectNextItem(false); | ||
SelectNextItem(false, false); | ||
e.Handled(true); | ||
} | ||
else | ||
{ | ||
SelectNextItem(true); | ||
SelectNextItem(true, false); | ||
e.Handled(true); | ||
} | ||
} | ||
|
@@ -161,13 +164,25 @@ namespace winrt::TerminalApp::implementation | |
if (key == VirtualKey::Up) | ||
{ | ||
// Action Mode: Move focus to the next item in the list. | ||
SelectNextItem(false); | ||
SelectNextItem(false, false); | ||
e.Handled(true); | ||
} | ||
else if (key == VirtualKey::Down) | ||
{ | ||
// Action Mode: Move focus to the previous item in the list. | ||
SelectNextItem(true); | ||
SelectNextItem(true, false); | ||
e.Handled(true); | ||
} | ||
else if (key == VirtualKey::PageUp) | ||
{ | ||
// Action Mode: Move focus to the previous item in the list. | ||
SelectNextItem(false, true); | ||
e.Handled(true); | ||
} | ||
else if (key == VirtualKey::PageDown) | ||
{ | ||
// Action Mode: Move focus to the previous item in the list. | ||
SelectNextItem(true, true); | ||
zadjii-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
e.Handled(true); | ||
} | ||
else if (key == VirtualKey::Enter) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document the new parameter