Localstorage somewhat

This commit is contained in:
2024-05-01 23:19:26 -05:00
parent badbd7e142
commit 72e980a2db
2 changed files with 13 additions and 13 deletions
-11
View File
@@ -93,16 +93,5 @@ export default {
} }
return 'quote' return 'quote'
} }
},
indent: function (state, textAfter, cx) {
return 0
//const closing = dedentPartial.test(textAfter);
//return state.basecol + cx.unit * (state.indentDepth - (closing ? 1 : 0));
},
languageData: {
//indentOnInput: /^\s*(?:end|until|else|\)|\})$/,
//commentTokens: {line: '//', block: {open: '/*', close: '*/'}}
} }
} }
+13 -2
View File
@@ -10,11 +10,22 @@ export default function({ src: defaultSrc }) {
const [binary, setBinary] = useState(null) // The assembled binary const [binary, setBinary] = useState(null) // The assembled binary
const [cpu, _setCpu] = useState(() => new WasmCPU()) // The actual CPU emulator const [cpu, _setCpu] = useState(() => new WasmCPU()) // The actual CPU emulator
const [errors, setErrors] = useState(null) // What's displayed on the compile errors tab const [errors, setErrors] = useState(null) // What's displayed on the compile errors tab
const [src, setSrc] = useState(() => undent(defaultSrc)) // The current Forge source
const [status, setStatus] = useState('') // The contents of the status bar const [status, setStatus] = useState('') // The contents of the status bar
// Whether the emulator should be running. Has to be a ref because the CPU setTimeout loop won't ever see changes in it otherwise // Whether the emulator should be running. Has to be a ref because the CPU setTimeout loop won't ever see changes in it otherwise
const running = useRef(false) const running = useRef(false)
// The current Forge source. Our initial state tries to look something up from localStorage,
// then if that fails uses the prop.
const [src, setSrc] = useState(() => {
return window.localStorage.getItem('src') || undent(defaultSrc)
})
// When we update the src, also update the key in localStorage
const updateSrc = useCallback((newSrc) => {
setSrc(newSrc)
window.localStorage.setItem('src', newSrc)
}, [])
// Callback for the build button // Callback for the build button
const build = useCallback(() => { const build = useCallback(() => {
try { try {
@@ -65,7 +76,7 @@ export default function({ src: defaultSrc }) {
<Tabbar activeTab={activeTab} setActiveTab={setActiveTab} anyErrors={!!errors}/> <Tabbar activeTab={activeTab} setActiveTab={setActiveTab} anyErrors={!!errors}/>
<Toolbar activeTab={activeTab} running={running.current} build={build} run={run} stop={stop}/> <Toolbar activeTab={activeTab} running={running.current} build={build} run={run} stop={stop}/>
<div className='content'> <div className='content'>
{activeTab === 'editor' && <ForgeEditor build={build} run={run} updateSrc={setSrc} src={src}/>} {activeTab === 'editor' && <ForgeEditor build={build} run={run} updateSrc={updateSrc} src={src}/>}
{activeTab === 'assembly' && <pre>{assembly}</pre>} {activeTab === 'assembly' && <pre>{assembly}</pre>}
{activeTab === 'display' && <EmulatorDisplay cpu={cpu}/>} {activeTab === 'display' && <EmulatorDisplay cpu={cpu}/>}
{activeTab === 'errors' && <pre>{errors}</pre>} {activeTab === 'errors' && <pre>{errors}</pre>}