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

Move current selected/highlighted song with arrow keys. #161

Open
PixelPotts opened this issue Jun 20, 2024 · 4 comments
Open

Move current selected/highlighted song with arrow keys. #161

PixelPotts opened this issue Jun 20, 2024 · 4 comments

Comments

@PixelPotts
Copy link
Collaborator

It would be nice if you could use the arrow keys to move up or down by a single song per keypress.

image

If I press the DOWN KEY, it will move the blue highlight cursor down to the next song or the UP KEY and previous song. Whether or not this should play the newly highlight song... I do not know. Currently the arrows move the scroll bar by a small amount up or down, and I presume no one uses this intentionally for scrolling as it is cucumbersome.

A nice touch might be to keep the cursor centered vertically in the container such that moving up or down "moves" the list but the highlight remains in position. Ideally this would not be a hard anchoring to the center, but a small window in which the cursor can move around without affecting the position of the list; when it goes out of that bound above or below, then the list itself moves, keeping the cursor in that box.

I mean, moving in the light gray area (below image) would not reposition/scroll the list, but would only move the cursor. Outside of the light gray area, the cursor stays put and the list scrolls.

image

@mmontag
Copy link
Owner

mmontag commented Jun 21, 2024

Ah yes, List View selectable row behavior. Of course, this is a must-have for any software purporting to honor Winamp. Something that Spotify does (YouTube Music doesn't and Rdio never did).

I've put it off until now, waiting for someone to request it. I want to hear from the people.

If I can piggyback the browser's built-in focus mechanism, then we get the "selection following" behavior for free...

@mmontag
Copy link
Owner

mmontag commented Jun 21, 2024

items = null; fidx = 0; listview = document.querySelector('.App-main-content-area'); window.addEventListener('keydown', e => { if (!['ArrowUp','ArrowDown'].includes(e.key)) return; e.preventDefault(); items = listview.querySelectorAll('a'); if (e.key === 'ArrowUp') { fidx = Math.max(0, fidx-1); } if (e.key === 'ArrowDown') { fidx = Math.min(items.length-1, fidx+1); } items.item(fidx).focus(); }); document.styleSheets[0].insertRule('.App-main-content-area>div>div>div:focus-within{box-shadow: 0 0 0 10px inset #66d6}');

@mmontag
Copy link
Owner

mmontag commented Jul 31, 2024

I am still working on this. Don't worry, it's coming

@mmontag
Copy link
Owner

mmontag commented Aug 2, 2024

Still working on this. Remember, I have to make it work with list virtualization.

And there are surprising edge cases to be resolved.

For example, if you select row 30, then scroll it out of view with the mouse wheel, and then press enter, it needs to start playing row 30, even though row 30 no longer exists in the component tree/DOM (due to virtualization). And then row 30 should be scrolled back into view so you can see what just happened.

Ultimately the browser's built in focus mechanisms do not work with virtualization. Because when you scroll the focused element out of view, it is removed from the DOM, and the browser resets focus to the body element. Therefore, the browser focus should be fixed to the virtual scroll element, and a synthetic focus must be maintained within it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants