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

Also maintain selected item in quick pick when updating items #138355

Closed
roblourens opened this issue Dec 2, 2021 · 4 comments
Closed

Also maintain selected item in quick pick when updating items #138355

roblourens opened this issue Dec 2, 2021 · 4 comments
Assignees
Labels
quick-pick Quick-pick widget issues under-discussion Issue is under discussion for relevance, priority, approach

Comments

@roblourens
Copy link
Member

Testing #137740

Similarly to keepScrollPosition, it would be useful to have a flag to maintain the selected item. There is no ID on items but you could maintain it by index or by just comparing the properties of QuickPickItems to find the one which matches the previously selected item.

@TylerLeonhardt
Copy link
Member

As you've pointed out, we don't have a good way to say for sure that yes that item is same as that one after setting .items. However, the API already lets you set qp.activeItems so you can just do either something like:

const previouslySelected = qp.activeItems;
qp.items = newListWithSameObjReferences;
qp.activeItems = previouslySelected;

or something like:

const indexesOfPreviouslySelected = qp.activeItems.map(item => qp.items.indexOf(item));
qp.items = newListWithDifferentObjReferences;
qp.activeItems = indexesOfPreviouslySelected.map(i => qp.items[i])

or if they use an id:

const idsOfPrevious = qp.activeItems.map(item => item.id);
qp.items = newListWithDifferentObjReferences;
qp.activeItems = idsOfPrevious.map(id => qp.items.find(item => item === id));

I don't think it's worth having QP logic to attempt to best effort these cases...

@TylerLeonhardt TylerLeonhardt added under-discussion Issue is under discussion for relevance, priority, approach quick-pick Quick-pick widget issues labels Dec 3, 2021
@TylerLeonhardt
Copy link
Member

cc @bpasero and @chrmarti if they wanna join the discussion.

@roblourens
Copy link
Member Author

Oh, I missed that the extension can set that. That is probably the right solution then.

@TylerLeonhardt
Copy link
Member

I'll close this but feel free to reopen if you wanna have a discussion

@github-actions github-actions bot locked and limited conversation to collaborators Jan 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
quick-pick Quick-pick widget issues under-discussion Issue is under discussion for relevance, priority, approach
Projects
None yet
Development

No branches or pull requests

2 participants