Allow vector widget only on vector expressions. (#9596)

Fixes #9593

<img width="426" alt="image" src="https://github.com/enso-org/enso/assets/919491/a794a023-420d-4358-8068-252d8d136a57">
This commit is contained in:
Paweł Grabarz 2024-04-02 15:41:58 +02:00 committed by GitHub
parent 9db264231e
commit 84c8535587
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View File

@ -44,7 +44,7 @@ const navigator = injectGraphNavigator(true)
</script>
<script lang="ts">
export const widgetDefinition = defineWidget(WidgetInput.isAstOrPlaceholder, {
export const widgetDefinition = defineWidget(WidgetInput.placeholderOrAstMatcher(Ast.Vector), {
priority: 500,
score: (props) =>
props.input.dynamicConfig?.kind === 'Vector_Editor' ? Score.Perfect

View File

@ -36,6 +36,12 @@ export namespace WidgetInput {
input.value instanceof nodeType
}
/** Match input against a placeholder or specific AST node type. */
export function placeholderOrAstMatcher<T extends Ast.Ast>(nodeType: new (...args: any[]) => T) {
return (input: WidgetInput): input is WidgetInput & { value: T } =>
isPlaceholder(input) || input.value instanceof nodeType
}
export function isAst(input: WidgetInput): input is WidgetInput & { value: Ast.Ast } {
return input.value instanceof Ast.Ast
}