simplify rollback

This commit is contained in:
Joeri Exelmans 2025-05-12 11:26:37 +02:00
parent ebae0afc81
commit 0a9dbd454f
4 changed files with 57 additions and 26 deletions

View file

@ -8,16 +8,7 @@ import { Type } from "./Type";
import "./Editor.css"
import { focusNextElement, focusPrevElement } from "./util/dom_trickery";
interface LetInBlockState {
kind: "let";
env: any;
name: string;
value: EditorState;
inner: EditorState;
resolved: undefined | Dynamic;
rollback?: EditorState;
}
import type { LetInBlockState } from "./LetInBlock";
interface LambdaBlockState {
kind: "lambda";
@ -50,7 +41,7 @@ interface EditorProps extends State2Props<EditorState> {
const dontFilter = () => true;
function getCommands(type) {
const commands = ['u', 't', 'Enter', 'Backspace', 'ArrowLeft', 'Tab'];
const commands = ['u', 't', 'Enter', 'Backspace', 'ArrowLeft', 'Tab', 'l', '='];
if (getSymbol(type) === symbolFunction) {
commands.push('c');
}
@ -114,6 +105,21 @@ export function Editor({state, setState, onResolve, onCancel}: EditorProps) {
focusPrevElement();
return;
}
// l -> Let ... in ...
// = -> assign to name
if (e.key === 'l' || e.key === '=') {
// we become LetInBlock
setState({
kind: "let",
env: state.env,
inner: initialEditorState,
name: "",
value: state,
resolved: undefined,
rollback: state,
});
return;
}
};
const renderBlock = () => {