diff --git a/packages/supersearch/src/lib/components/SuperSearch.svelte b/packages/supersearch/src/lib/components/SuperSearch.svelte index 1a734354b..d4810ca9d 100644 --- a/packages/supersearch/src/lib/components/SuperSearch.svelte +++ b/packages/supersearch/src/lib/components/SuperSearch.svelte @@ -2,7 +2,7 @@ import { onMount, onDestroy, type Snippet } from 'svelte'; import CodeMirror, { type ChangeCodeMirrorEvent } from '$lib/components/CodeMirror.svelte'; import { EditorView, placeholder as placeholderExtension, keymap } from '@codemirror/view'; - import { Compartment, type Extension } from '@codemirror/state'; + import { Compartment, StateEffect, type Extension } from '@codemirror/state'; import { type LanguageSupport } from '@codemirror/language'; import submitFormOnEnterKey from '$lib/extensions/submitFormOnEnterKey.js'; import preventNewLine from '$lib/extensions/preventNewLine.js'; @@ -63,6 +63,16 @@ } }); + const onDataUpdateEffect = StateEffect.define<{ message: string }>({}); + + $effect(() => { + if (search.data) { + const effects = { effects: onDataUpdateEffect.of({ message: 'new_data' }) }; + expandedEditorView?.dispatch(effects); + collapsedEditorView?.dispatch(effects); + } + }); + const extensionsWithDefaults = [ keymap.of(standardKeymap), // Needed for atomic ranges to work. Maybe we can use a subset? submitFormOnEnterKey(form), diff --git a/packages/supersearch/src/lib/extensions/lxlQualifierPlugin/index.ts b/packages/supersearch/src/lib/extensions/lxlQualifierPlugin/index.ts index 6c2daf700..b56ecc9c6 100644 --- a/packages/supersearch/src/lib/extensions/lxlQualifierPlugin/index.ts +++ b/packages/supersearch/src/lib/extensions/lxlQualifierPlugin/index.ts @@ -155,6 +155,14 @@ function lxlQualifierPlugin(getLabelFn?: GetLabelFunction) { update(update: ViewUpdate) { if (update.docChanged || syntaxTree(update.startState) != syntaxTree(update.state)) { this.qualifiers = getQualifiers(update.view); + } else { + for (const tr of update.transactions) { + for (const e of tr.effects) { + if (e.value.message === 'new_data') { + this.qualifiers = getQualifiers(update.view); + } + } + } } } },