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

Board hotkeys now work when board is not selected #290

Merged
merged 9 commits into from
Apr 30, 2024
35 changes: 22 additions & 13 deletions app/Components/Sudoku Board/SudokuBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,30 @@ const SudokuBoard = (props: SudokuBoardProps) => {
};

const handleKeyDown = (event: any) => {
const inputValue = event.nativeEvent.key;

if (inputValue == "u" || inputValue == "U") {
Gregory711 marked this conversation as resolved.
Show resolved Hide resolved
const isUndoButtonDisabled =
sudokuBoard.actionHistory == null ||
sudokuBoard.actionHistory.length == 0;
if (!isUndoButtonDisabled) {
undo();
}
} else if (inputValue == "p" || inputValue == "P") {
handlePause(sudokuBoard, navigation);
} else if (
inputValue == "t" ||
inputValue == "T" ||
inputValue == "n" ||
inputValue == "N"
) {
toggleNoteMode();
}

if (sudokuBoard.selectedCell == null) {
return;
}

const inputValue = event.nativeEvent.key;
if (/^[1-9]$/.test(inputValue)) {
updateCellEntry(parseInt(inputValue, 10));
} else if (
Gregory711 marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -449,18 +468,7 @@ const SudokuBoard = (props: SudokuBoardProps) => {
inputValue == "E" // e and E are for erase
) {
eraseSelected();
} else if (inputValue == "u" || inputValue == "U") {
undo();
} else if (inputValue == "p" || inputValue == "P") {
handlePause(sudokuBoard, navigation);
} else if (
inputValue == "t" ||
inputValue == "T" ||
inputValue == "n" ||
inputValue == "N"
) {
toggleNoteMode();
} else if (sudokuBoard.selectedCell) {
} else {
Gregory711 marked this conversation as resolved.
Show resolved Hide resolved
let newCol = sudokuBoard.selectedCell.c;
let newRow = sudokuBoard.selectedCell.r;
switch (inputValue) {
Expand Down Expand Up @@ -567,6 +575,7 @@ const SudokuBoard = (props: SudokuBoardProps) => {
return (
<View
testID={"sudokuBoard"}
//@ts-ignore react-native-web types not supported: https://github.com/necolas/react-native-web/issues/1684
onKeyDown={handleKeyDown}
style={{
alignItems: "center",
Expand Down
Loading