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

impr(commandline): scroll active entry into view when searchbar is empty (JayTailor45) #4663

Merged
merged 14 commits into from
Oct 2, 2023

Conversation

JayTailor45
Copy link
Contributor

Description

It improves language selection dropdown by adding scroll into view. Now selected values will be automatically scrolled into view.

Closes #4662

#4662

@monkeytypegeorge monkeytypegeorge added the frontend User interface or web stuff label Sep 25, 2023
Copy link
Member

@Miodec Miodec left a 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.

@JayTailor45
Copy link
Contributor Author

@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
        );
      }
    }
  }
}

@Miodec
Copy link
Member

Miodec commented Sep 25, 2023

The animation is still there and the element is still scrolled to the top instead of the center.

@Miodec
Copy link
Member

Miodec commented Sep 25, 2023

The results are also not scrolled to the top.

@Miodec
Copy link
Member

Miodec commented Sep 25, 2023

Steps to test with:

Set language to russian.
Open the commandline, go to the language selection.
The results should snap to russian being in the middle. (currently russian is begin snapped to the top)
As soon as i start typing, for example wanting to switch to spanish, the results should snap to the top (currently after pressing s, they are still scrolled down)

@JayTailor45 JayTailor45 changed the title fix: language selection scroll into view impr: language selection scroll into view Sep 26, 2023
@JayTailor45
Copy link
Contributor Author

@Miodec I've made changes as you mentioned. Please check it and let me know if any changes require. Thanks!

Steps to test with:

Set language to russian. Open the commandline, go to the language selection. The results should snap to russian being in the middle. (currently russian is begin snapped to the top) As soon as i start typing, for example wanting to switch to spanish, the results should snap to the top (currently after pressing s, they are still scrolled down)

@Miodec
Copy link
Member

Miodec commented Sep 26, 2023

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.

@JayTailor45
Copy link
Contributor Author

JayTailor45 commented Sep 26, 2023

Oh I thought it was intentional. No worries. I will make the change ;)

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.

@JayTailor45
Copy link
Contributor Author

@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!

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.

@Miodec Miodec added the waiting for review Pull requests that require a review before continuing label Sep 29, 2023
$(".suggestions").scrollTop(0);
} else {
const suggestions = $(".suggestions");
const scrollTarget = $(".suggestions .entry .icon i.fa-check");
Copy link
Member

@Miodec Miodec Oct 2, 2023

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.

Copy link
Member

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.

@JayTailor45
Copy link
Contributor Author

@Miodec thanks for the feedback. I have refactored the code to use the existing keepActiveEntryInView().

@Miodec
Copy link
Member

Miodec commented Oct 2, 2023

Well done, thanks.

@Miodec Miodec changed the title impr: language selection scroll into view impr(commandline): scroll active entry into view when searchbar is empty (JayTailor45) Oct 2, 2023
@Miodec Miodec merged commit d2a6b89 into monkeytypegame:master Oct 2, 2023
8 checks passed
@JayTailor45
Copy link
Contributor Author

My pleasure! Thank you for the opportunity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend User interface or web stuff waiting for review Pull requests that require a review before continuing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Commandline: Scroll selected element into view when opening
3 participants