Destructuring: Instead of accessing e.ctrlKey, e.metaKey, e.target, and e.code separately, we can destructure these properties directly in the function parameters. This makes the code cleaner and easier to read.

testing_refactoring
richrobber2 2024-06-12 04:04:54 -07:00
parent 4330e06ebe
commit b1fadac08d
1 changed files with 6 additions and 7 deletions

View File

@ -1194,23 +1194,22 @@ onUiLoaded(async () => {
* Handles key down events to trigger moving operations on the canvas.
* @param {KeyboardEvent} event - The keyboard event object.
*/
const handleMoveKeyDown = (e) => {
const handleMoveKeyDown = ({ ctrlKey, metaKey, target, code }) => {
const allowedKeys = ['KeyV', 'KeyC', 'F5'];
const isCtrlPressed = e.ctrlKey || e.metaKey; // Combine Ctrl and Meta (Cmd) keys
const isTyping = ['TEXTAREA', 'INPUT'].includes(e.target.nodeName);
const isCtrlPressed = ctrlKey || metaKey; // Combine Ctrl and Meta (Cmd) keys
const isTyping = ['TEXTAREA', 'INPUT'].includes(target.nodeName);
const shouldPreventDefault =
(isTyping && !hotkeysConfig.canvas_blur_prompt) || (isCtrlPressed && allowedKeys.includes(e.code));
(isTyping && !hotkeysConfig.canvas_blur_prompt) || (isCtrlPressed && allowedKeys.includes(code));
if (shouldPreventDefault || e.code !== hotkeysConfig.canvas_hotkey_move || !isKeyDownHandlerAttached) {
if (shouldPreventDefault || code !== hotkeysConfig.canvas_hotkey_move || !isKeyDownHandlerAttached) {
return;
}
e.preventDefault();
event.preventDefault();
document.activeElement.blur();
isMoving = true;
};
/**
* Handles key up events to stop moving operations on the canvas.
* @param {KeyboardEvent} event - The keyboard event object.