can disable syntactic sugar also for let...in... blocks + nicer looking fn input parameters
This commit is contained in:
parent
e850952738
commit
d7a4e210a2
4 changed files with 19 additions and 13 deletions
|
|
@ -3,12 +3,13 @@ import { useContext, useEffect, useRef } from "react";
|
|||
|
||||
import { Editor, type EditorState } from "./Editor";
|
||||
import { EnvContext } from "./EnvContext";
|
||||
import { evalEditorBlock, evalLetInBlock, makeInnerEnv, scoreResolved } from "./eval";
|
||||
import { evalEditorBlock, makeInnerEnv, scoreResolved } from "./eval";
|
||||
import { type State2Props } from "./Editor";
|
||||
import { autoInputWidth } from "./util/dom_trickery";
|
||||
|
||||
import "./LetInBlock.css";
|
||||
import type { SuggestionType } from "./InputBlock";
|
||||
import { CommandContext } from "./CommandContext";
|
||||
|
||||
export interface LetInBlockState {
|
||||
kind: "let";
|
||||
|
|
@ -35,13 +36,14 @@ export function LetInBlock({state, setState, suggestionPriority}: LetInBlockProp
|
|||
state={state}
|
||||
setState={setState}
|
||||
suggestionPriority={suggestionPriority}
|
||||
/>
|
||||
/>
|
||||
</div>
|
||||
</span>
|
||||
}
|
||||
|
||||
function DeclColumns({state, setState, suggestionPriority}) {
|
||||
const env = useContext(EnvContext);
|
||||
const globalContext = useContext(CommandContext);
|
||||
const {name, value, inner} = state;
|
||||
|
||||
const setInner = callback => setState(state => ({...state, inner: callback(state.inner)}));
|
||||
|
|
@ -86,8 +88,8 @@ function DeclColumns({state, setState, suggestionPriority}) {
|
|||
onCancel={() => setState(state => state.inner)} // keep inner
|
||||
/>
|
||||
</span>
|
||||
{/* <span className="keyword column">in</span> */}
|
||||
{inner.kind === "let" &&
|
||||
globalContext?.syntacticSugar &&
|
||||
<EnvContext value={innerEnv}>
|
||||
<DeclColumns
|
||||
state={inner}
|
||||
|
|
@ -101,11 +103,12 @@ function DeclColumns({state, setState, suggestionPriority}) {
|
|||
|
||||
function InnerMost({state, setState, suggestionPriority}) {
|
||||
const env = useContext(EnvContext);
|
||||
const globalContext = useContext(CommandContext);
|
||||
const setInner = callback => setState(state => ({...state, inner: callback(state.inner)}));
|
||||
const valueResolved = evalEditorBlock(state.value, env);
|
||||
const innerEnv = makeInnerEnv(env, state.name, valueResolved);
|
||||
const onCancel = () => setState(state => state.value);
|
||||
if (state.inner.kind === "let") {
|
||||
if (state.inner.kind === "let" && globalContext?.syntacticSugar) {
|
||||
return <EnvContext value={innerEnv}>
|
||||
<InnerMost
|
||||
state={state.inner}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue