Skip to content
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

Merged
21 commits merged into from Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions src/cascadia/TerminalApp/CommandPalette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,51 @@ namespace winrt::TerminalApp::implementation
_filteredActionsView().ScrollIntoView(_filteredActionsView().SelectedItem());
}

// Method Description:
// - Scrolls the focus up or down the list of commands.
// Arguments:
// - pageDown: if true, we're attempting to move to last visible item in the
// list. Otherwise, we're attempting to move to first visible item.
// Return Value:
// - <none>
void CommandPalette::ScrollDown(const bool pageDown)
{
const auto container = _filteredActionsView().ContainerFromIndex(0);
const auto item = container.try_as<winrt::Windows::UI::Xaml::Controls::ListViewItem>();
const auto itemHeight = ::base::saturated_cast<int>(item.ActualHeight());
const auto listHeight = ::base::saturated_cast<int>(_filteredActionsView().ActualHeight());
const int numVisibleItems = listHeight / itemHeight;
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved

auto selected = _filteredActionsView().SelectedIndex();
const int numItems = ::base::saturated_cast<int>(_filteredActionsView().Items().Size());

const auto newIndex = ((numItems + selected + (pageDown ? numVisibleItems : -numVisibleItems)) % numItems);
_filteredActionsView().SelectedIndex(newIndex);
_filteredActionsView().ScrollIntoView(_filteredActionsView().SelectedItem());
}

// Method Description:
// - Moves the focus either to top item or end item in the list of commands.
// Arguments:
// - end: if true, we're attempting to move to last item in the
// list. Otherwise, we're attempting to move to first item.
// Depends on the pageUpDown argument.
// Return Value:
// - <none>
void CommandPalette::GoEnd(const bool end)
{
const auto lastIndex = ::base::saturated_cast<int>(_filteredActionsView().Items().Size() - 1);
if (end)
{
_filteredActionsView().SelectedIndex(lastIndex);
}
else
{
_filteredActionsView().SelectedIndex(0);
}
_filteredActionsView().ScrollIntoView(_filteredActionsView().SelectedItem());
}

// Method Description:
// - Called when the command selection changes. We'll use this in the tab
// switcher to "preview" tabs as the user navigates the list of tabs. To
Expand Down Expand Up @@ -193,6 +238,28 @@ namespace winrt::TerminalApp::implementation
SelectNextItem(true);
e.Handled(true);
}
else if (key == VirtualKey::PageUp)
{
// Action Mode: Move focus to the previous item in the list.
ScrollDown(false);
e.Handled(true);
}
else if (key == VirtualKey::PageDown)
{
// Action Mode: Move focus to the previous item in the list.
ScrollDown(true);
e.Handled(true);
}
else if (key == VirtualKey::Home)
{
GoEnd(false);
e.Handled(true);
}
else if (key == VirtualKey::End)
{
GoEnd(true);
e.Handled(true);
}
else if (key == VirtualKey::Enter)
{
// Action, TabSwitch or TabSearchMode Mode: Dispatch the action of the selected command.
Expand Down
4 changes: 4 additions & 0 deletions src/cascadia/TerminalApp/CommandPalette.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ namespace winrt::TerminalApp::implementation

void SelectNextItem(const bool moveDown);

void ScrollDown(const bool pageDown);

void GoEnd(const bool end);

// Tab Switcher
void EnableTabSwitcherMode(const bool searchMode, const uint32_t startIdx);
void OnTabsChanged(const Windows::Foundation::IInspectable& s, const Windows::Foundation::Collections::IVectorChangedEventArgs& e);
Expand Down