From 230916ceb1848a9f0ad17e02847b496e4ceddf06 Mon Sep 17 00:00:00 2001 From: Joeri Exelmans Date: Tue, 20 May 2025 14:53:24 +0200 Subject: [PATCH] refactor a bit --- src/App.tsx | 26 ++--- src/ExprBlock.css | 5 - src/ExprBlock.tsx | 199 ++++++++++----------------------------- src/Input.tsx | 156 ++++++++++++++++++++++++++++++ src/InputBlock.tsx | 132 +++++++------------------- src/LambdaBlock.tsx | 47 +++------ src/LetInBlock.tsx | 32 +++---- src/Type.css | 2 + src/actions.ts | 60 ++++++++++++ src/eval.ts | 24 ++--- src/util/dom_trickery.ts | 56 ----------- src/util/parse.ts | 1 - 12 files changed, 342 insertions(+), 398 deletions(-) create mode 100644 src/Input.tsx create mode 100644 src/actions.ts delete mode 100644 src/util/dom_trickery.ts delete mode 100644 src/util/parse.ts diff --git a/src/App.tsx b/src/App.tsx index c2cce23..53e2171 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -4,14 +4,8 @@ import { ExprBlock, type ExprBlockState } from './ExprBlock'; import { GlobalContext } from './GlobalContext'; import { biggerExample, higherOrder, higherOrder2Params, inc, initialEditorState, lambda2Params, nonEmptyEditorState, pushBool, tripleFunctionCallEditorState } from "./configurations"; import { removeFocus } from "./eval"; +import { actionShortcuts, getActions } from './actions'; -const commands: [string, string[], string][] = [ - ["call" , ['c' ], "call" ], - ["eval" , ['e','Tab','Enter'], "eval" ], - ["transform", ['t', '.' ], "transform" ], - ["let" , ['l', '=' ], "let … in …" ], - ["lambda" , ['a' ], "λx: …" ], -]; const examples: [string, ExprBlockState][] = [ ["empty editor" , initialEditorState ], @@ -114,9 +108,9 @@ export function App() { }, []); const [highlighted, setHighlighted] = useState( - commands.map(() => false)); + actionShortcuts.map(() => false)); - const doHighlight = Object.fromEntries(commands.map(([id], i) => { + const doHighlight = Object.fromEntries(actionShortcuts.map(([id], i) => { return [id, () => { setHighlighted(h => h.with(i, true)); setTimeout(() => setHighlighted(h => h.with(i, false)), 100); @@ -138,9 +132,10 @@ export function App() { { - commands.map(([_, keys, descr], i) => + actionShortcuts.map(([_, keys, descr], i) => {keys.map((key, j) => {key})} +   {descr} ) } @@ -173,18 +168,11 @@ export function App() { // console.log('suggestionPriority of App, always 0'); return 0; }} - addParam={(s: ExprBlockState) => { - pushHistory(state => ({ - kind: "call", - fn: removeFocus(state), - input: initialEditorState, - })); - doHighlight.call(); + addParam={() => { + getActions({doHighlight}, pushHistory).c(); }} /> - -