Files
0b838dc3c4 [READY] BYOND 516 compatability (#25105)
* Preliminary changes for 516

* Also removes the goon folder

* Fixes a BUNCH of UIs

* update our things

* debug proc

* le maintainer verb

* fix strip panel

* browseroutput => chat_panel

* prettier, remove obsolete bat

* tidu tgui say css

* href purge

* 515 compat

* 515 compat 2

* more required chores

* comments

* fully working 515

* bungle

* correct this

* fixes 515 support

* prettier

* new CI

* fixes old href styles sneaking in

* update docs to reflect href changes

* more href fixes (thanks cdui)

* MORE href nonsense

* even more hrefs (seriously wtf)

* Update code/modules/admin/permissionverbs/permissionedit.dm

* error on fail

---------

Co-authored-by: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com>
2024-04-15 18:49:50 +00:00

48 lines
1.3 KiB
JavaScript

/**
* Basically, hacks from goonchat which try to keep the map focused at all
* times, except for when some meaningful action happens o
*
* @file
* @copyright 2020 Aleksej Komarov
* @license MIT
*/
import { vecLength, vecSubtract } from 'common/vector';
import { canStealFocus, globalEvents } from 'tgui/events';
import { focusMap } from 'tgui/focus';
// Empyrically determined number for the smallest possible
// text you can select with the mouse.
const MIN_SELECTION_DISTANCE = 10;
const deferredFocusMap = () => setTimeout(() => focusMap());
export const setupPanelFocusHacks = () => {
let focusStolen = false;
let clickStartPos = null;
window.addEventListener('focusin', (e) => {
focusStolen = canStealFocus(e.target);
});
window.addEventListener('mousedown', (e) => {
clickStartPos = [e.screenX, e.screenY];
});
window.addEventListener('mouseup', (e) => {
if (clickStartPos) {
const clickEndPos = [e.screenX, e.screenY];
const dist = vecLength(vecSubtract(clickEndPos, clickStartPos));
if (dist >= MIN_SELECTION_DISTANCE) {
focusStolen = true;
}
}
if (!focusStolen) {
deferredFocusMap();
}
});
globalEvents.on('keydown', (key) => {
if (key.isModifierKey()) {
return;
}
deferredFocusMap();
});
};