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

Enable PgUp/PgDown and Home/End in the command palette #7835

21 commits merged into from Oct 22, 2020

Conversation

ghost
Copy link

@ghost ghost commented Oct 6, 2020

Closes #7729

@ghost ghost added Area-User Interface Issues pertaining to the user interface of the Console or Terminal Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal. labels Oct 6, 2020
@DHowett
Copy link
Member

DHowett commented Oct 6, 2020

Hey there! You can keep updating the same pull request, you don’t have to make a new one every time! 😄 it might be a little easier for you to manage that way!

@zadjii-msft
Copy link
Member

My only real qualm with this PR is hardcoding the height to 42. I'd really rather not do that, and use the ActualHeight of the individual ListViewItem at runtime. However, I'm not positive that there's actually a way to do that. I don't know if it's possible to get a singular ListViewItem from a list view, which seems bizarre to me

@ghost
Copy link
Author

ghost commented Oct 8, 2020

Yes I don't like it is being hardcoded either. I will try a little bit more.

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);
Copy link
Contributor

Choose a reason for hiding this comment

The 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

{
const auto listHeight = ::base::saturated_cast<int>(_filteredActionsView().ActualHeight());
const int numVisibleItems = listHeight / 42;
Copy link
Contributor

Choose a reason for hiding this comment

The 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

// - 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document the new parameter

@ghost
Copy link
Author

ghost commented Oct 10, 2020

I've been trying to generate ListViewItem in CommandPalette.xaml.g.h like _filteredActionView() is so that I can access a height property of ListViewItem, but I keep failing it. Though it's possible right ?

@DHowett
Copy link
Member

DHowett commented Oct 13, 2020

I wonder if we can get rid of the 42 by using... ListView::ContainerFromIndex() and measuring the object it gives us to get its ActualHeight()?

@ghost
Copy link
Author

ghost commented Oct 14, 2020

I have no idea how to measure the object that I got from ListView::ContainerFromIndex(). I have been trying to get top y coordinate and bottom y coordinate of the object and subtract one from another, but I just can not do it. Or is there specific API to measure the height of it ?

@ghost
Copy link
Author

ghost commented Oct 14, 2020

Is this commit better than before? At least hardcoded 42 is removed.

previous commit was draft
Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened to trying ContainerFromIndex? Does the following work to get the item's height?

        auto f = _filteredActionsView().ContainerFromIndex(0);
        auto g = f.try_as<winrt::Windows::UI::Xaml::Controls::ListViewItem>();
        auto h = g.ActualHeight();

I think that should work, but g might end up being null. If it is, I'd maybe try casting it to a FrameworkElement instead

{
const auto itemHeight = ::base::saturated_cast<int>(_parentCommandText().Height());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't take a dependency on the height of the parentCommandText element, there's not necessarily a guarantee that element is the same height as the items of the list view

src/cascadia/TerminalApp/CommandPalette.xaml Outdated Show resolved Hide resolved
@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Oct 15, 2020
Using ListView::ContainerFromIndex() and casted into ListViewItem to get its ActualHeight
@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Oct 16, 2020
Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As much as I hate this ternary, I'd rather get this in for now and file a follow-up PR to clean it up. Someone else on the team can override that opinion though. Thanks for your patience!

src/cascadia/TerminalApp/CommandPalette.cpp Show resolved Hide resolved
src/cascadia/TerminalApp/CommandPalette.cpp Outdated Show resolved Hide resolved
@zadjii-msft zadjii-msft added the Needs-Second It's a PR that needs another sign-off label Oct 21, 2020
Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! This is great. I'm going to address my own comment about the App.xaml file and merge it.

We need to manually create the error text brush as a
theme-dependent brush. SystemControlErrorTextForegroundBrush
is unfortunately static.
-->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't totally understand why this file changed

Copy link
Author

@ghost ghost Oct 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I don't either. Sorry for the mess.

@DHowett
Copy link
Member

DHowett commented Oct 22, 2020

This is excellent work. 😄

@DHowett DHowett changed the title enabling page up/down button Enable PgUp/PgDown and Home/End in the command palette Oct 22, 2020
@DHowett DHowett added the AutoMerge Marked for automatic merge by the bot when requirements are met label Oct 22, 2020
@ghost
Copy link

ghost commented Oct 22, 2020

Hello @DHowett!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@microsoft-github-updates microsoft-github-updates bot changed the base branch from master to main October 22, 2020 00:27
@DHowett
Copy link
Member

DHowett commented Oct 22, 2020

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@ghost
Copy link

ghost commented Oct 22, 2020

Apologies, while this PR appears ready to be merged, it looks like main is a protected branch and I have not been granted permission to perform the merge.

@DHowett DHowett added AutoMerge Marked for automatic merge by the bot when requirements are met and removed AutoMerge Marked for automatic merge by the bot when requirements are met labels Oct 22, 2020
@ghost ghost merged commit 293ad27 into microsoft:main Oct 22, 2020
@ghost ghost deleted the fet/7729-pageUpDown branch October 22, 2020 09:33
DHowett pushed a commit that referenced this pull request Oct 27, 2020
@ghost
Copy link

ghost commented Nov 11, 2020

🎉Windows Terminal v1.4.3141.0 has been released which incorporates this pull request.:tada:

Handy links:

@ghost
Copy link

ghost commented Nov 11, 2020

🎉Windows Terminal Preview v1.5.3142.0 has been released which incorporates this pull request.:tada:

Handy links:

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-User Interface Issues pertaining to the user interface of the Console or Terminal AutoMerge Marked for automatic merge by the bot when requirements are met hacktoberfest-accepted Issue-Task It's a feature request, but it doesn't really need a major design. Needs-Second It's a PR that needs another sign-off Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Command Palette should support page up/down to move faster thru the options
4 participants