From 9ead113555f9fcc778293b5746850af05f314c79 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Sat, 27 Apr 2024 22:23:48 +0200 Subject: [PATCH] Fix some crashes in TagRenderingQuestion --- .../TagRendering/TagRenderingQuestion.svelte | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte b/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte index 61de4e84c..9bf63d639 100644 --- a/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte +++ b/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte @@ -31,6 +31,7 @@ import { TrashIcon } from "@rgossiaux/svelte-heroicons/solid" import { Tag } from "../../../Logic/Tags/Tag" import { get } from "svelte/store" + import Markdown from "../../Base/Markdown.svelte" export let config: TagRenderingConfig export let tags: UIEventSource> @@ -68,15 +69,17 @@ /** * Prepares and fills the checkedMappings */ - function initialize(tgs: Record, confg: TagRenderingConfig): void{ + function initialize(tgs: Record, confg: TagRenderingConfig): void { mappings = confg.mappings?.filter((m) => { if (typeof m.hideInAnswer === "boolean") { return !m.hideInAnswer } return !m.hideInAnswer.matchesProperties(tgs) }) - selectedMapping = mappings.findIndex(mapping => mapping.if.matchesProperties(tgs) || mapping.alsoShowIf?.matchesProperties(tgs)) - + selectedMapping = mappings?.findIndex(mapping => mapping.if.matchesProperties(tgs) || mapping.alsoShowIf?.matchesProperties(tgs)) + if(selectedMapping < 0){ + selectedMapping = undefined + } // We received a new config -> reinit unit = layer?.units?.find((unit) => unit.appliesToKeys.has(config.freeform?.key)) @@ -99,7 +102,7 @@ seenFreeforms.push(newProps[confg.freeform.key]) } return matches - }), + }) ] if (tgs !== undefined && confg.freeform) { @@ -207,7 +210,7 @@ dispatch("saved", { config, applied: selectedTags }) const change = new ChangeTagAction(tags.data.id, selectedTags, tags.data, { theme: tags.data["_orig_theme"] ?? state.layout.id, - changeType: "answer", + changeType: "answer" }) freeformInput.set(undefined) selectedMapping = undefined @@ -259,15 +262,19 @@ {#if config.questionhint} -
- -
+ {#if config.questionHintIsMd} + + {:else} +
+ +
+ {/if} {/if}