further improved keyboard handling
This commit is contained in:
parent
95eb8aef84
commit
fa70d2f3f4
5 changed files with 38 additions and 13 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { useState } from "react";
|
||||
|
||||
import { apply, UnifyError, assignFn, getType } from "dope2";
|
||||
import { apply, UnifyError, assignFn, getType, getSymbol, symbolFunction } from "dope2";
|
||||
|
||||
import { Editor, type EditorState } from "./Editor";
|
||||
import { Value } from "./Value";
|
||||
|
|
@ -97,7 +97,8 @@ export function CallBlock({ state, setState, onResolve }: CallBlockProps) {
|
|||
<FunctionHeader
|
||||
fn={state.fn}
|
||||
setFn={setFn}
|
||||
onFnResolve={onFnResolve} />
|
||||
onFnResolve={onFnResolve}
|
||||
input={state.input} />
|
||||
<div className="functionParams">
|
||||
<div className="outputParam">
|
||||
{/* Sequence of input parameters */}
|
||||
|
|
@ -116,7 +117,7 @@ export function CallBlock({ state, setState, onResolve }: CallBlockProps) {
|
|||
</span>;
|
||||
}
|
||||
|
||||
function FunctionHeader({ fn, setFn, onFnResolve }) {
|
||||
function FunctionHeader({ fn, setFn, input, onFnResolve }) {
|
||||
if (fn.kind === "call") {
|
||||
// if the function we're calling is itself the result of a function call,
|
||||
// then we are anonymous, and so we don't draw a function name
|
||||
|
|
@ -129,9 +130,28 @@ function FunctionHeader({ fn, setFn, onFnResolve }) {
|
|||
return <FunctionHeader
|
||||
fn={fn.fn}
|
||||
setFn={fnFn => setFn({...fn, fn: fnFn})}
|
||||
onFnResolve={onFnFnResolve} />;
|
||||
onFnResolve={onFnFnResolve}
|
||||
input={fn.input} />;
|
||||
}
|
||||
else {
|
||||
const filterCompatibleFns = ([_name, dynamic]: [string, Dynamic]) => {
|
||||
if (input.resolved) {
|
||||
try {
|
||||
const type = getType(dynamic);
|
||||
if (getSymbol(type) !== symbolFunction) {
|
||||
return false;
|
||||
}
|
||||
assignFn(type, getType(input.resolved));
|
||||
} catch (e) {
|
||||
if (!(e instanceof UnifyError)) {
|
||||
throw e;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// end of recursion - draw function name
|
||||
return <div className="functionName">
|
||||
𝑓𝑛
|
||||
|
|
@ -141,7 +161,7 @@ function FunctionHeader({ fn, setFn, onFnResolve }) {
|
|||
focus={false}
|
||||
onResolve={onFnResolve}
|
||||
onCancel={() => {/*todo*/}}
|
||||
filter={() => true} />
|
||||
filter={filterCompatibleFns} />
|
||||
</div>;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue