refactor a bit
This commit is contained in:
parent
4fee37944d
commit
230916ceb1
12 changed files with 342 additions and 398 deletions
60
src/actions.ts
Normal file
60
src/actions.ts
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import { initialEditorState } from "./configurations";
|
||||
import { removeFocus } from "./eval";
|
||||
|
||||
export const actionShortcuts: [string, string[], string][] = [
|
||||
["call" , ['c'], "expr ⌴" ],
|
||||
["transform", ['.'], "⌴ 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();
|
||||
},
|
||||
'.': () => {
|
||||
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();
|
||||
},
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue