Destructuring: Instead of accessing e.deltaY multiple times, we can destructure it directly in the function parameters. This makes the code cleaner and easier to read.

Early Return: Instead of wrapping the adjustBrushSize call in an if statement, we can return early if the condition is not met. This reduces the level of indentation and makes the code more readable.

Implicit Return: In arrow functions, if the function body consists of a single statement, you can omit the braces and the return keyword. This makes the code more concise. However, in this case, we need to explicitly return false to prevent the default action.
testing_refactoring
richrobber2 2024-06-12 04:01:46 -07:00
parent 37d49a66b4
commit 4330e06ebe
1 changed files with 7 additions and 8 deletions

View File

@ -1175,20 +1175,19 @@ onUiLoaded(async () => {
});
/**
* Event listener for wheel event on the target element to handle zoom and brush size adjustment.
*/
targetElement.addEventListener("wheel", (e) => {
* Event listener for wheel event on the target element to handle zoom and brush size adjustment.
*/
targetElement.addEventListener("wheel", ({ deltaY }) => {
const isDefaultCanvas = checkIsDefault(elementIDs, elemId);
if (!isDefaultCanvas || !window.applyZoomAndPan) {
const operation = e.deltaY > 0 ? "-" : "+";
changeZoomLevel(operation, e);
changeZoomLevel(deltaY > 0 ? "-" : "+", deltaY);
}
if (!isModifierKey(e, hotkeysConfig.canvas_hotkey_adjust)) return;
if (!isModifierKey(deltaY, hotkeysConfig.canvas_hotkey_adjust)) return;
e.preventDefault();
adjustBrushSize(elemId, e.deltaY, false, hotkeysConfig.canvas_zoom_brush_size_change);
adjustBrushSize(elemId, deltaY, false, hotkeysConfig.canvas_zoom_brush_size_change);
return false;
});
/**