fix suggestion order
This commit is contained in:
parent
46baad7cf4
commit
1ff4b181ff
8 changed files with 91 additions and 168 deletions
|
|
@ -1,15 +1,13 @@
|
|||
import { useContext, useEffect, useRef } from "react";
|
||||
|
||||
|
||||
import { Editor, type EditorState } from "./Editor";
|
||||
import { EnvContext } from "./EnvContext";
|
||||
import { evalEditorBlock, makeInnerEnv, scoreResolved } from "./eval";
|
||||
import { evalEditorBlock, makeInnerEnv, scoreResolved, type ResolvedType } from "./eval";
|
||||
import { type State2Props } from "./Editor";
|
||||
import { autoInputWidth } from "./util/dom_trickery";
|
||||
import { GlobalContext } from "./GlobalContext";
|
||||
|
||||
import "./LetInBlock.css";
|
||||
import type { SuggestionType } from "./InputBlock";
|
||||
import { CommandContext } from "./CommandContext";
|
||||
|
||||
export interface LetInBlockState {
|
||||
kind: "let";
|
||||
|
|
@ -18,9 +16,7 @@ export interface LetInBlockState {
|
|||
inner: EditorState;
|
||||
}
|
||||
|
||||
interface LetInBlockProps extends State2Props<LetInBlockState,EditorState> {
|
||||
suggestionPriority: (suggestion: SuggestionType) => number;
|
||||
}
|
||||
interface LetInBlockProps extends State2Props<LetInBlockState,EditorState> {}
|
||||
|
||||
export function LetInBlock({state, setState, suggestionPriority}: LetInBlockProps) {
|
||||
return <span className="letIn">
|
||||
|
|
@ -43,7 +39,7 @@ export function LetInBlock({state, setState, suggestionPriority}: LetInBlockProp
|
|||
|
||||
function DeclColumns({state, setState, suggestionPriority}) {
|
||||
const env = useContext(EnvContext);
|
||||
const globalContext = useContext(CommandContext);
|
||||
const globalContext = useContext(GlobalContext);
|
||||
const {name, value, inner} = state;
|
||||
|
||||
const setInner = callback => setState(state => ({...state, inner: callback(state.inner)}));
|
||||
|
|
@ -52,8 +48,8 @@ function DeclColumns({state, setState, suggestionPriority}) {
|
|||
setState(state => ({...state, name: e.target.value}));
|
||||
}
|
||||
|
||||
const valueSuggestionPriority = (suggestion: SuggestionType) => {
|
||||
const innerEnv = makeInnerEnv(env, name, suggestion[2]);
|
||||
const valueSuggestionPriority = (suggestion: ResolvedType) => {
|
||||
const innerEnv = makeInnerEnv(env, name, suggestion);
|
||||
const resolved = evalEditorBlock(inner, innerEnv);
|
||||
return scoreResolved(resolved, suggestionPriority);
|
||||
};
|
||||
|
|
@ -103,7 +99,7 @@ function DeclColumns({state, setState, suggestionPriority}) {
|
|||
|
||||
function InnerMost({state, setState, suggestionPriority}) {
|
||||
const env = useContext(EnvContext);
|
||||
const globalContext = useContext(CommandContext);
|
||||
const globalContext = useContext(GlobalContext);
|
||||
const setInner = callback => setState(state => ({...state, inner: callback(state.inner)}));
|
||||
const valueResolved = evalEditorBlock(state.value, env);
|
||||
const innerEnv = makeInnerEnv(env, state.name, valueResolved);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue