hitting spacebar always adds a parameter to the first ancestor that is a CallBlock
This commit is contained in:
parent
5b6bcf5ffa
commit
5c3018b8c7
8 changed files with 140 additions and 43 deletions
|
|
@ -6,9 +6,12 @@ import { EnvContext } from "./EnvContext";
|
|||
import type { Dynamic, ResolvedType } from "./eval";
|
||||
import "./InputBlock.css";
|
||||
import { Type } from "./Type";
|
||||
import type { State2Props } from "./ExprBlock";
|
||||
import type { ExprBlockState, State2Props } from "./ExprBlock";
|
||||
import { autoInputWidth, focusNextElement, focusPrevElement, setRightMostCaretPosition } from "./util/dom_trickery";
|
||||
import { attemptParseLiteral } from "./eval";
|
||||
import { attemptParseLiteral, removeFocus } from "./eval";
|
||||
import { GlobalContext } from "./GlobalContext";
|
||||
import { initialEditorState } from "./configurations";
|
||||
import type { CallBlockState } from "./CallBlock";
|
||||
|
||||
interface Literal {
|
||||
kind: "literal";
|
||||
|
|
@ -32,8 +35,9 @@ export interface InputBlockState {
|
|||
export type SuggestionType = ['literal'|'name', string, Dynamic];
|
||||
export type PrioritizedSuggestionType = [number, ...SuggestionType];
|
||||
|
||||
interface InputBlockProps extends State2Props<InputBlockState> {
|
||||
interface InputBlockProps extends State2Props<InputBlockState,ExprBlockState> {
|
||||
onCancel: () => void;
|
||||
addParam: (e: ExprBlockState) => void;
|
||||
}
|
||||
|
||||
const computeSuggestions = (text, env, suggestionPriority: (s: ResolvedType) => number): PrioritizedSuggestionType[] => {
|
||||
|
|
@ -55,11 +59,12 @@ const computeSuggestions = (text, env, suggestionPriority: (s: ResolvedType) =>
|
|||
]
|
||||
// return []; // <-- uncomment to disable suggestions (useful for debugging)
|
||||
return ls
|
||||
.map(suggestion => [suggestionPriority(suggestion[2]), ...suggestion] as PrioritizedSuggestionType)
|
||||
.map((suggestion) => [suggestionPriority(suggestion[2]), ...suggestion] as PrioritizedSuggestionType)
|
||||
.sort(([priorityA], [priorityB]) => priorityB - priorityA)
|
||||
}
|
||||
|
||||
export function InputBlock({ state, setState, suggestionPriority, onCancel }: InputBlockProps) {
|
||||
export function InputBlock({ state, setState, suggestionPriority, onCancel, addParam }: InputBlockProps) {
|
||||
const globalContext = useContext(GlobalContext);
|
||||
const {text, focus} = state;
|
||||
const env = useContext(EnvContext);
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
|
|
@ -147,7 +152,13 @@ export function InputBlock({ state, setState, suggestionPriority, onCancel }: In
|
|||
onCancel();
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
},
|
||||
" ": () => {
|
||||
e.preventDefault();
|
||||
if (text.length > 0) {
|
||||
addParam(initialEditorState);
|
||||
}
|
||||
},
|
||||
};
|
||||
fns[e.key]?.();
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue