simplify some things

This commit is contained in:
Joeri Exelmans 2025-05-13 13:11:57 +02:00
parent fa70d2f3f4
commit 9ef160aeb7
8 changed files with 105 additions and 30 deletions

View file

@ -2,6 +2,7 @@ import { useEffect, useRef, useState } from 'react';
import './App.css'
import { Editor, type EditorState } from './Editor'
import { initialEditorState, nonEmptyEditorState, tripleFunctionCallEditorState } from "./configurations";
import { CommandContext } from './CommandContext';
export function App() {
const [history, setHistory] = useState([initialEditorState]);
@ -48,22 +49,48 @@ export function App() {
window.onkeydown = onKeyDown;
}, []);
const commands = [
["call" , "[c] call" ],
["eval" , "[u] [Tab] [Enter] eval"],
["transform", "[t] transform" ],
["let" , "[=] let ... in ..." ],
];
const [highlighted, setHighlighted] = useState(
commands.map(() => false));
const doHighlight = Object.fromEntries(commands.map(([id], i) => {
return [id, () => {
setHighlighted(h => h.with(i, true));
setTimeout(() => setHighlighted(h => h.with(i, false)), 100);
}];
}));
return (
<>
<header>
<button disabled={history.length===1} onClick={onUndo}>Undo ({history.length-1}) [Ctrl+Z]</button>
<button disabled={future.length===0} onClick={onRedo}>Redo ({future.length}) [Ctrl+Shift+Z]</button>
Commands:
{
commands.map(([_, descr], i) =>
<span key={i} className={'command' + (highlighted[i] ? (' highlighted') : '')}>
{descr}
</span>)
}
</header>
<main>
<Editor
state={history.at(-1)!}
setState={pushHistory}
onResolve={() => {}}
onCancel={() => {}}
filter={() => true}
focus={true}
/>
<CommandContext value={doHighlight}>
<Editor
state={history.at(-1)!}
setState={pushHistory}
onResolve={() => {}}
onCancel={() => {}}
filter={() => true}
focus={true}
/>
</CommandContext>
</main>
<footer>