-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
impr(commandline): scroll active entry into view when searchbar is empty (JayTailor45) #4663
Conversation
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.
Please remove the animation and only animate if the $("#commandLine input").val()
is empty, otherwise scroll to top.
@Miodec I have updated the code. Now my function looks like this. Can you please let me know best way to test both cases? function scrollSelectedLanguageToView(): void {
const suggestions = $(".suggestions");
const scrollTarget = $(".suggestions .entry .icon i.fa-check");
if (suggestions.length && scrollTarget.length) {
const paddingOffset = 8;
const suggestionsOffset = suggestions.offset();
const scrollTargetOffset = scrollTarget.offset();
if (suggestionsOffset && scrollTargetOffset) {
if (!$("#commandLine input").val()) {
$(".suggestions").animate(
{
scrollTop:
scrollTargetOffset.top - suggestionsOffset.top - paddingOffset,
},
500
);
} else {
$(".suggestions").scrollTop(
scrollTargetOffset.top - suggestionsOffset.top - paddingOffset
);
}
}
}
} |
The animation is still there and the element is still scrolled to the top instead of the center. |
The results are also not scrolled to the top. |
Steps to test with: Set language to |
@Miodec I've made changes as you mentioned. Please check it and let me know if any changes require. Thanks!
|
Another issue is that if you scroll the list to the currently active element, the selected element is still the first one, making it a bit confusing. |
Oh I thought it was intentional. No worries. I will make the change ;)
|
@Miodec I've added the active element logic as you asked. Please check it and let me know. also let me know if you need squashed commit. Thanks!
|
frontend/src/ts/commandline/index.ts
Outdated
$(".suggestions").scrollTop(0); | ||
} else { | ||
const suggestions = $(".suggestions"); | ||
const scrollTarget = $(".suggestions .entry .icon i.fa-check"); |
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.
It looks like this .suggestions .entry .icon i.fa-check
element check is used both here and in updateSuggested
. I think instead of always scrolling the checked element into view, we convert this function to be a more generic scrollActiveEntryToCenter()
which scrolls an entry to center which has an index of activeIndex
(global variable in this file)
Also, i would move the if ($("#commandLine input").val())
check to the updateSuggested()
funciton aswell.
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.
I just realised there is a function for that already - keepActiveEntryInView()
. I think this whole function is not needed.
@Miodec thanks for the feedback. I have refactored the code to use the existing |
Well done, thanks. |
My pleasure! Thank you for the opportunity. |
Description
It improves language selection dropdown by adding scroll into view. Now selected values will be automatically scrolled into view.
Closes #4662
#4662