diff --git a/code/modules/tgui/tgui_input_list.dm b/code/modules/tgui/tgui_input_list.dm index 242b69a9347..d56042d4572 100644 --- a/code/modules/tgui/tgui_input_list.dm +++ b/code/modules/tgui/tgui_input_list.dm @@ -82,6 +82,7 @@ src.message = message src.buttons = list() src.buttons_map = list() + var/list/repeat_buttons = list() // Gets rid of illegal characters var/static/regex/whitelistedWords = regex(@{"([^\u0020-\u8000]+)"}) @@ -89,6 +90,9 @@ for(var/i in buttons) var/string_key = whitelistedWords.Replace("[i]", "") + //avoids duplicated keys E.g: when areas have the same name + string_key = avoid_assoc_duplicate_keys(string_key, repeat_buttons) + src.buttons += string_key src.buttons_map[string_key] = i diff --git a/tgui/packages/tgui/interfaces/ListInput.js b/tgui/packages/tgui/interfaces/ListInput.js index 721ac4f5ac6..be6a3599a15 100644 --- a/tgui/packages/tgui/interfaces/ListInput.js +++ b/tgui/packages/tgui/interfaces/ListInput.js @@ -7,11 +7,9 @@ import { clamp01 } from 'common/math'; import { useBackend, useLocalState } from '../backend'; import { Box, Button, Section, Input, Stack } from '../components'; +import { KEY_DOWN, KEY_UP, KEY_ENTER, KEY_SPACE } from 'common/keycodes'; import { Window } from '../layouts'; -const ARROW_KEY_UP = 38; -const ARROW_KEY_DOWN = 40; - let lastScrollTime = 0; export const ListInput = (props, context) => { @@ -48,9 +46,9 @@ export const ListInput = (props, context) => { } lastScrollTime = performance.now() + 125; - if (e.keyCode === ARROW_KEY_UP || e.keyCode === ARROW_KEY_DOWN) { + if (e.keyCode === KEY_UP || e.keyCode === KEY_DOWN) { let direction = 1; - if (e.keyCode === ARROW_KEY_UP) direction = -1; + if (e.keyCode === KEY_UP) direction = -1; let index = 0; for (index; index < buttons.length; index++) { @@ -65,6 +63,11 @@ export const ListInput = (props, context) => { return; } + if (e.keyCode === KEY_SPACE || e.keyCode === KEY_ENTER) { + act("choose", { choice: selectedButton }); + return; + } + const charCode = String.fromCharCode(e.keyCode).toLowerCase(); if (!charCode) return;