diff --git a/src/components/BaseModal.vue b/src/components/BaseModal.vue index 91d1d14..4e54e99 100644 --- a/src/components/BaseModal.vue +++ b/src/components/BaseModal.vue @@ -1,7 +1,7 @@ + + + + diff --git a/src/components/CustomFunctionsModal.vue b/src/components/CustomFunctionsModal.vue index c0ace01..a09944c 100644 --- a/src/components/CustomFunctionsModal.vue +++ b/src/components/CustomFunctionsModal.vue @@ -6,9 +6,10 @@ * and a form shared by both "new" and "edit". See the plan's "Bedienung" * section for the exact mockups this follows. */ -import { reactive, ref, watch } from 'vue'; +import { nextTick, reactive, ref, watch } from 'vue'; import { useDocument } from '../store/document'; import BaseModal from './BaseModal.vue'; +import CodeReference from './CodeReference.vue'; const props = defineProps<{ open: boolean }>(); const emit = defineEmits<{ (e: 'close'): void }>(); @@ -87,6 +88,20 @@ function removeFunction(id: string, name: string) { } } +const bodyInput = ref(null); + +/** Put a reference snippet at the caret (replacing any selection). */ +async function insertSnippet(text: string) { + const el = bodyInput.value; + const start = el?.selectionStart ?? form.body.length; + const end = el?.selectionEnd ?? form.body.length; + form.body = form.body.slice(0, start) + text + form.body.slice(end); + await nextTick(); + if (!el) return; + el.focus(); + el.setSelectionRange(start + text.length, start + text.length); +} + function close() { emit('close'); } @@ -95,6 +110,7 @@ function close() { -