dope2-webapp/src/component/app/actions.ts
2025-05-23 22:35:47 +02:00

62 lines
1.6 KiB
TypeScript

import { initialEditorState } from "./configurations";
// import { removeFocus } from "./eval";
const removeFocus = state => state;
export const actionShortcuts: [string, string[], string][] = [
["call" , ['c'], "expr ⌴" ],
["transform", ['t'], "⌴ expr" ],
["assign" , ['a'], "let (⌴ = expr) in ⌴"],
["declare" , ['d'], "let (⌴ = ⌴) in expr"],
["lambda" , ['l'], "λ⌴. expr" ],
];
export function getActions(globalContext, setState) {
return {
c: () => {
setState(state => ({
kind: "call",
fn: removeFocus(state),
input: initialEditorState,
}));
globalContext?.doHighlight.call();
},
t: () => {
setState(state => ({
kind: "call",
fn: initialEditorState,
input: removeFocus(state),
}));
globalContext?.doHighlight.transform();
},
a: () => {
setState(state => ({
kind: "let",
name: "",
focus: true,
value: removeFocus(state),
inner: removeFocus(initialEditorState),
}));
globalContext?.doHighlight.assign();
},
d: () => {
setState(state => ({
kind: "let",
name: "",
focus: true,
value: removeFocus(initialEditorState),
inner: removeFocus(state),
}));
globalContext?.doHighlight.declare();
},
l: () => {
setState(state => ({
kind: "lambda",
paramName: "",
focus: true,
expr: removeFocus(state),
}));
globalContext?.doHighlight.lambda();
},
};
}