mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-24 13:38:41 +01:00
[MIRROR] tgui input list improvements (#6405)
* tgui input list improvements (#59668) pressing enter or space now selects the selected button duplicate keys no longer cause input lists to break * tgui input list improvements Co-authored-by: LatteKat <56778689+jupyterkat@users.noreply.github.com>
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user