Refactor shortcuts into a central file and fix issue with caps lock
This commit is contained in:
@@ -11,6 +11,8 @@ import { useKeyboard } from "../../contexts/KeyboardContext";
|
||||
|
||||
import Vector2 from "../../helpers/Vector2";
|
||||
|
||||
import shortcuts from "../../shortcuts";
|
||||
|
||||
function MapGridEditor({ map, onGridChange }) {
|
||||
const stageScale = useDebouncedStageScale();
|
||||
const mapWidth = useMapWidth();
|
||||
@@ -166,20 +168,19 @@ function MapGridEditor({ map, onGridChange }) {
|
||||
}
|
||||
|
||||
function handleKeyDown(event) {
|
||||
const { key, shiftKey } = event;
|
||||
const nudgeAmount = shiftKey ? 2 : 0.5;
|
||||
if (key === "ArrowUp") {
|
||||
const nudgeAmount = event.shiftKey ? 2 : 0.5;
|
||||
if (shortcuts.gridNudgeUp(event)) {
|
||||
// Stop arrow up/down scrolling if overflowing
|
||||
event.preventDefault();
|
||||
nudgeGrid({ x: 0, y: -1 }, nudgeAmount);
|
||||
}
|
||||
if (key === "ArrowLeft") {
|
||||
if (shortcuts.gridNudgeLeft(event)) {
|
||||
nudgeGrid({ x: -1, y: 0 }, nudgeAmount);
|
||||
}
|
||||
if (key === "ArrowRight") {
|
||||
if (shortcuts.gridNudgeRight(event)) {
|
||||
nudgeGrid({ x: 1, y: 0 }, nudgeAmount);
|
||||
}
|
||||
if (key === "ArrowDown") {
|
||||
if (shortcuts.gridNudgeDown(event)) {
|
||||
event.preventDefault();
|
||||
nudgeGrid({ x: 0, y: 1 }, nudgeAmount);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user