[qol][ui] add cursor wrap around to option select menus (#3518)

This commit is contained in:
MokaStitcher 2024-08-13 22:33:59 +02:00 committed by GitHub
parent e9c89b437b
commit 267772c043
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 1 deletions

View File

@ -197,11 +197,15 @@ export default abstract class AbstractOptionSelectUiHandler extends UiHandler {
case Button.UP:
if (this.cursor) {
success = this.setCursor(this.cursor - 1);
} else if (this.cursor === 0) {
success = this.setCursor(options.length -1);
}
break;
case Button.DOWN:
if (this.cursor < options.length - 1) {
success = this.setCursor(this.cursor + 1);
} else {
success = this.setCursor(0);
}
break;
}
@ -268,11 +272,13 @@ export default abstract class AbstractOptionSelectUiHandler extends UiHandler {
let isScroll = false;
const options = this.getOptionsWithScroll();
if (changed && this.config?.maxOptions && this.config.options.length > this.config.maxOptions) {
const optionsScrollTotal = options.length;
if (Math.abs(cursor - this.cursor) === options.length - 1) {
// Wrap around the list
const optionsScrollTotal = this.config.options.length;
this.scrollCursor = cursor ? optionsScrollTotal - (this.config.maxOptions - 1) : 0;
this.setupOptions();
} else {
// Move the cursor up or down by 1
const isDown = cursor && cursor > this.cursor;
if (isDown) {
if (options[cursor].label === scrollDownLabel) {