This commit is contained in:
Adria Navarro 2025-02-13 13:12:15 +01:00
parent 31d375cd22
commit 47a0f6e9cf
1 changed files with 19 additions and 9 deletions

View File

@ -70,6 +70,7 @@
let expressionLogs: Log[] | undefined let expressionLogs: Log[] | undefined
let expressionError: string | undefined let expressionError: string | undefined
let evaluating = false let evaluating = false
let completions: BindingCompletion[] = []
$: useSnippets = allowSnippets && !$licensing.isFreePlan $: useSnippets = allowSnippets && !$licensing.isFreePlan
$: editorModeOptions = getModeOptions(allowHBS, allowJS) $: editorModeOptions = getModeOptions(allowHBS, allowJS)
@ -90,11 +91,20 @@
$: requestEval(runtimeExpression, context, snippets) $: requestEval(runtimeExpression, context, snippets)
$: bindingCompletions = bindingsToCompletions(enrichedBindings, editorMode) $: bindingCompletions = bindingsToCompletions(enrichedBindings, editorMode)
$: bindingHelpers = new BindingHelpers(getCaretPosition, insertAtPos) $: bindingHelpers = new BindingHelpers(getCaretPosition, insertAtPos)
$: hbsCompletions = getHBSCompletions(bindingCompletions)
$: jsCompletions = getJSCompletions(bindingCompletions, snippets, { $: {
if (mode === BindingMode.Text) {
completions = getHBSCompletions(bindingCompletions)
} else if (mode === BindingMode.JavaScript) {
completions = getJSCompletions(bindingCompletions, snippets, {
useHelpers: allowHelpers, useHelpers: allowHelpers,
useSnippets, useSnippets,
}) })
} else {
completions = []
}
}
$: { $: {
// Ensure a valid side panel option is always selected // Ensure a valid side panel option is always selected
if (sidePanel && !sidePanelOptions.includes(sidePanel)) { if (sidePanel && !sidePanelOptions.includes(sidePanel)) {
@ -365,13 +375,13 @@
{/if} {/if}
<div class="editor"> <div class="editor">
{#if mode === BindingMode.Text} {#if mode === BindingMode.Text}
{#key hbsCompletions} {#key completions}
<CodeEditor <CodeEditor
value={hbsValue} value={hbsValue}
on:change={onChangeHBSValue} on:change={onChangeHBSValue}
bind:getCaretPosition bind:getCaretPosition
bind:insertAtPos bind:insertAtPos
completions={hbsCompletions} {completions}
autofocus={autofocusEditor} autofocus={autofocusEditor}
placeholder={placeholder || placeholder={placeholder ||
"Add bindings by typing {{ or use the menu on the right"} "Add bindings by typing {{ or use the menu on the right"}
@ -379,11 +389,11 @@
/> />
{/key} {/key}
{:else if mode === BindingMode.JavaScript} {:else if mode === BindingMode.JavaScript}
{#key jsCompletions} {#key completions}
<CodeEditor <CodeEditor
value={jsValue ? decodeJSBinding(jsValue) : jsValue} value={jsValue ? decodeJSBinding(jsValue) : jsValue}
on:change={onChangeJSValue} on:change={onChangeJSValue}
completions={jsCompletions} {completions}
mode={EditorModes.JS} mode={EditorModes.JS}
bind:getCaretPosition bind:getCaretPosition
bind:insertAtPos bind:insertAtPos