Skip to content

Commit e6d2288

Browse files
authored
Auto expand text area for system prompt (#25)
* quick fix to prompt textbox auto-expanding * proper fix for prompt textbox auto-expanding * formatting fix
1 parent f27a412 commit e6d2288

File tree

1 file changed

+37
-8
lines changed

1 file changed

+37
-8
lines changed

ui/components/prompts/add-edit.vue

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@
266266
name="system-prompt"
267267
id="system-prompt"
268268
ref="systemPromptTextarea"
269-
:rows="getTextareaRows(systemPrompt, 5, 15)"
269+
@input="autoResizeSystemPrompt"
270270
class="block w-full border-2 border-black dark:border-white bg-white dark:bg-neutral-800 p-2 text-base text-neutral-900 dark:text-white focus:outline-none sm:text-sm/6"
271271
/>
272272
</div>
@@ -281,7 +281,7 @@
281281
name="user-prompt"
282282
id="user-prompt"
283283
ref="userPromptTextarea"
284-
:rows="getTextareaRows(userPrompt, 1, 15)"
284+
@input="autoResizeUserPrompt"
285285
class="block w-full border-2 border-black dark:border-white bg-white dark:bg-neutral-800 p-2 text-base text-neutral-900 dark:text-white focus:outline-none sm:text-sm/6"
286286
/>
287287
</div>
@@ -328,6 +328,7 @@ import type { Model } from '~/types/response/models';
328328
import type { PromptCreateDTO, PromptUpdateDTO } from '~/types/components/prompt';
329329
import type { SchemaValidationResponse } from '~/types/response/schema';
330330
import { useDebounceFn } from '@vueuse/core';
331+
import { ref, watch, computed, nextTick, onMounted } from 'vue';
331332
332333
const props = defineProps<{
333334
prompt: Prompt | null
@@ -502,14 +503,42 @@ function selectModel(model: Model) {
502503
}
503504
}
504505
505-
// Auto-expand textarea based on content, respecting min and max rows
506-
function getTextareaRows(text: string, minRows: number, maxRows: number): number {
507-
if (!text) return minRows;
508-
509-
const lineCount = (text.match(/\n/g) || []).length + 1;
510-
return Math.min(Math.max(lineCount, minRows), maxRows);
506+
// Auto-expand textarea height based on content
507+
const systemPromptTextarea = ref<HTMLTextAreaElement | null>(null);
508+
const userPromptTextarea = ref<HTMLTextAreaElement | null>(null);
509+
510+
function autoResizeSystemPrompt() {
511+
nextTick(() => {
512+
const el = systemPromptTextarea.value;
513+
if (el) {
514+
el.style.height = 'auto';
515+
el.style.height = el.scrollHeight + 'px';
516+
}
517+
});
518+
}
519+
520+
function autoResizeUserPrompt() {
521+
nextTick(() => {
522+
const el = userPromptTextarea.value;
523+
if (el) {
524+
el.style.height = 'auto';
525+
el.style.height = el.scrollHeight + 'px';
526+
}
527+
});
511528
}
512529
530+
// Optionally, auto-resize on mount and when value changes
531+
onMounted(() => {
532+
autoResizeSystemPrompt();
533+
autoResizeUserPrompt();
534+
});
535+
watch(systemPrompt, () => {
536+
autoResizeSystemPrompt();
537+
});
538+
watch(userPrompt, () => {
539+
autoResizeUserPrompt();
540+
});
541+
513542
514543
// Computed property for validation errors
515544
const validationErrors = computed(() => {

0 commit comments

Comments
 (0)