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

Fix Hotkeys TGUI lag and ctrl + r mapping #4196

Merged
merged 5 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions code/modules/client/tgui_macro.dm
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ GLOBAL_LIST_EMPTY(ui_data_keybindings)
if(!ui)
ui = new(user, src, "KeyBinds", "Keybind Preference")
ui.open()
ui.set_autoupdate(FALSE)

/datum/tgui_macro/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
. = ..()
Expand Down
4 changes: 2 additions & 2 deletions tgui/packages/tgui/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ document.addEventListener('keydown', (e) => {
if (canStealFocus(e.target)) {
return;
}
const code = e.keyCode;
const code = e.code;
const key = new KeyEvent(e, 'keydown', keyHeldByCode[code]);
globalEvents.emit('keydown', key);
globalEvents.emit('key', key);
Expand All @@ -214,7 +214,7 @@ document.addEventListener('keyup', (e) => {
if (canStealFocus(e.target)) {
return;
}
const code = e.keyCode;
const code = e.code;
const key = new KeyEvent(e, 'keyup');
globalEvents.emit('keyup', key);
globalEvents.emit('key', key);
Expand Down
5 changes: 4 additions & 1 deletion tgui/packages/tgui/hotkeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ const keyCodeToByond = (keyCode: number) => {
const handlePassthrough = (key: KeyEvent) => {
const keyString = String(key);
// In addition to F5, support reloading with Ctrl+R and Ctrl+F5
if (keyString === 'Ctrl+F5' || keyString === 'Ctrl+R') {
if (
!key.event.defaultPrevented &&
(keyString === 'Ctrl+F5' || keyString === 'Ctrl+R')
) {
location.reload();
return;
}
Expand Down
11 changes: 5 additions & 6 deletions tgui/packages/tgui/interfaces/KeyBinds.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useBackend, useLocalState } from '../backend';
import { Button, Flex, Section, Box, Input, Dropdown } from '../components';
import { Window } from '../layouts';
import { globalEvents } from '../events.js';
import { createLogger } from '../logging';

const KEY_MODS = {
'SHIFT': true,
Expand Down Expand Up @@ -34,10 +33,6 @@ export const KeyBinds = (props, context) => {
? getAllKeybinds(glob_keybinds)
: glob_keybinds[selectedTab];

const logger = createLogger('waa');

logger.warn(keybinds_to_use);

const filteredKeybinds = keybinds_to_use.filter((val) =>
val.full_name.toLowerCase().match(searchTerm)
);
Expand Down Expand Up @@ -255,7 +250,7 @@ export class ButtonKeybind extends Component {

let pressedKey = e.key.toUpperCase();

this.finishTimerStart(200);
this.finishTimerStart(600);

// Prevents repeating
if (keysDown[pressedKey] && e.type === 'keydown') {
Expand Down Expand Up @@ -284,6 +279,8 @@ export class ButtonKeybind extends Component {
});
this.finishTimerStart(2000);
globalEvents.on('keydown', this.preventPassthrough);
globalEvents.on('key', this.preventPassthrough);
globalEvents.on('keyup', this.preventPassthrough);
}

doBlur() {
Expand All @@ -292,6 +289,8 @@ export class ButtonKeybind extends Component {
keysDown: {},
});
globalEvents.off('keydown', this.preventPassthrough);
globalEvents.off('key', this.preventPassthrough);
globalEvents.off('keyup', this.preventPassthrough);
}

render() {
Expand Down
Loading