From 267772c04398f1f2116e266dc43c3d4e0f3e0217 Mon Sep 17 00:00:00 2001 From: MokaStitcher <54149968+MokaStitcher@users.noreply.github.com> Date: Tue, 13 Aug 2024 22:33:59 +0200 Subject: [PATCH] [qol][ui] add cursor wrap around to option select menus (#3518) --- src/ui/abstact-option-select-ui-handler.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ui/abstact-option-select-ui-handler.ts b/src/ui/abstact-option-select-ui-handler.ts index ae7f107efc0..5172075da52 100644 --- a/src/ui/abstact-option-select-ui-handler.ts +++ b/src/ui/abstact-option-select-ui-handler.ts @@ -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) {