move 'env' from state to context
This commit is contained in:
parent
9ef160aeb7
commit
f09261df93
13 changed files with 178 additions and 148 deletions
|
|
@ -26,7 +26,7 @@ interface EditorProps extends State2Props<EditorState> {
|
|||
}
|
||||
|
||||
function getCommands(type) {
|
||||
const commands = ['u', 't', 'Enter', 'Backspace', 'ArrowLeft', 'ArrowRight', 'Tab', 'l', '='];
|
||||
const commands = ['u', 't', 'Enter', 'Backspace', 'ArrowLeft', 'ArrowRight', 'Tab', 'l', '=', '.'];
|
||||
if (getSymbol(type) === symbolFunction) {
|
||||
commands.push('c');
|
||||
}
|
||||
|
|
@ -34,9 +34,9 @@ function getCommands(type) {
|
|||
}
|
||||
function getShortCommands(type) {
|
||||
if (getSymbol(type) === symbolFunction) {
|
||||
return 'c|Tab|t';
|
||||
return 'c|Tab|.';
|
||||
}
|
||||
return 'Tab|t';
|
||||
return 'Tab|.';
|
||||
}
|
||||
|
||||
function removeFocus(state: EditorState): EditorState {
|
||||
|
|
@ -72,7 +72,7 @@ export function Editor({state, setState, onResolve, onCancel, filter}: EditorPro
|
|||
}
|
||||
}
|
||||
|
||||
const doHighlight = useContext(CommandContext);
|
||||
const globalContext = useContext(CommandContext);
|
||||
const onCommand = (e: React.KeyboardEvent) => {
|
||||
const type = getType(state.resolved);
|
||||
const commands = getCommands(type);
|
||||
|
|
@ -84,7 +84,7 @@ export function Editor({state, setState, onResolve, onCancel, filter}: EditorPro
|
|||
// u -> pass Up
|
||||
if (e.key === "u" || e.key === "Enter" || e.key === "Tab" && !e.shiftKey) {
|
||||
onResolve(state);
|
||||
doHighlight.eval();
|
||||
globalContext?.doHighlight.eval();
|
||||
return;
|
||||
}
|
||||
if (e.key === "Tab" && e.shiftKey) {
|
||||
|
|
@ -96,26 +96,24 @@ export function Editor({state, setState, onResolve, onCancel, filter}: EditorPro
|
|||
// we become CallBlock
|
||||
setState({
|
||||
kind: "call",
|
||||
env: state.env,
|
||||
fn: removeFocus(state),
|
||||
input: initialEditorState,
|
||||
resolved: undefined,
|
||||
});
|
||||
doHighlight.call();
|
||||
globalContext?.doHighlight.call();
|
||||
// focusNextElement();
|
||||
return;
|
||||
}
|
||||
// t -> Transform
|
||||
if (e.key === "t") {
|
||||
if (e.key === "t" || e.key === ".") {
|
||||
// we become CallBlock
|
||||
setState({
|
||||
kind: "call",
|
||||
env: state.env,
|
||||
fn: initialEditorState,
|
||||
input: removeFocus(state),
|
||||
resolved: undefined,
|
||||
});
|
||||
doHighlight.transform();
|
||||
globalContext?.doHighlight.transform();
|
||||
return;
|
||||
}
|
||||
if (e.key === "Backspace" || e.key === "ArrowLeft") {
|
||||
|
|
@ -132,13 +130,12 @@ export function Editor({state, setState, onResolve, onCancel, filter}: EditorPro
|
|||
// we become LetInBlock
|
||||
setState({
|
||||
kind: "let",
|
||||
env: state.env,
|
||||
inner: initialEditorState,
|
||||
inner: removeFocus(initialEditorState),
|
||||
name: "",
|
||||
value: state,
|
||||
value: removeFocus(state),
|
||||
resolved: undefined,
|
||||
});
|
||||
doHighlight.let();
|
||||
globalContext?.doHighlight.let();
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
|
@ -179,7 +176,7 @@ export function Editor({state, setState, onResolve, onCancel, filter}: EditorPro
|
|||
? <input
|
||||
ref={commandInputRef}
|
||||
spellCheck={false}
|
||||
className="editable command"
|
||||
className="editable commandInput"
|
||||
placeholder={`<command: ${getShortCommands(getType(state.resolved))}>`}
|
||||
onKeyDown={onCommand}
|
||||
value={""}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue