From 15e20e873a1832babc6213e1f623c74d8b0a46de Mon Sep 17 00:00:00 2001 From: Neta London Date: Sun, 29 Oct 2023 19:45:08 +0200 Subject: [PATCH] Fix memory reset to reset goto field as well --- components/src/chips/memory.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/components/src/chips/memory.tsx b/components/src/chips/memory.tsx index 4382f407d..e7226c88d 100644 --- a/components/src/chips/memory.tsx +++ b/components/src/chips/memory.tsx @@ -10,6 +10,7 @@ import { asm } from "@nand2tetris/simulator/util/asm.js"; import { bin, dec, hex } from "@nand2tetris/simulator/util/twos.js"; import InlineEdit from "../inline_edit.js"; import VirtualScroll, { VirtualScrollSettings } from "../virtual_scroll.js"; +import { useClockReset } from "../clockface.js"; const ITEM_HEIGHT = 34; @@ -129,11 +130,13 @@ export const Memory = ({ format: Format; }) => { const [fmt, setFormat] = useState(format); - const [jmp, setJmp] = useState("0"); + const [jmp, setJmp] = useState(""); const [goto, setGoto] = useState({ value: 0 }); const jumpTo = () => { - setGoto({ value: Number(jmp) }); + setGoto({ + value: !isNaN(parseInt(jmp)) && isFinite(parseInt(jmp)) ? Number(jmp) : 0, + }); }; // const { filePicker, fs } = useContext(AppContext); @@ -155,6 +158,11 @@ export const Memory = ({ [memory, fmt] ); + useClockReset(() => { + setJmp(""); + setGoto({value: 0}) + }); + return (
@@ -167,8 +175,9 @@ export const Memory = ({ key === "Enter" && jumpTo()} - onChange={({ target: { value } }) => setJmp(value ?? "0")} + onChange={({ target: { value } }) => setJmp(value)} />