hitting spacebar always adds a parameter to the first ancestor that is a CallBlock

This commit is contained in:
Joeri Exelmans 2025-05-20 09:02:19 +02:00
parent 5b6bcf5ffa
commit 5c3018b8c7
8 changed files with 140 additions and 43 deletions

View file

@ -470,4 +470,56 @@ function makeError(env: Environment, e: Error, unification: Unification=new Map(
nextFreeTypeVar: idx + 1,
typeVars: new Set([...env.typeVars, UNBOUND_SYMBOLS[idx]]),
}];
}
}
export function removeFocus(state: ExprBlockState): ExprBlockState {
if (state.kind === "input") {
return { ...state, focus: false };
}
else if (state.kind === "call") {
return {
...state,
fn: removeFocus(state.fn),
input: removeFocus(state.input),
};
}
else if (state.kind === "lambda") {
return {
...state,
focus: false,
expr: removeFocus(state.expr),
};
}
else { // state.kind === "let"
return {
...state,
focus: false,
value: removeFocus(state.value),
inner: removeFocus(state.inner),
}
}
}
export function addFocusRightMost(state: ExprBlockState) : ExprBlockState {
if (state.kind === "input") {
return { ...state, focus: true };
}
else if (state.kind === "call") {
return {
... state,
input: addFocusRightMost(state.input),
};
}
else if (state.kind === "lambda") {
return {
...state,
expr: addFocusRightMost(state.expr),
};
}
else { // state.kind === "let"
return {
...state,
inner: addFocusRightMost(state.inner),
}
}
}