|
266 | 266 | name="system-prompt"
|
267 | 267 | id="system-prompt"
|
268 | 268 | ref="systemPromptTextarea"
|
269 |
| - :rows="getTextareaRows(systemPrompt, 5, 15)" |
| 269 | + @input="autoResizeSystemPrompt" |
270 | 270 | 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"
|
271 | 271 | />
|
272 | 272 | </div>
|
|
281 | 281 | name="user-prompt"
|
282 | 282 | id="user-prompt"
|
283 | 283 | ref="userPromptTextarea"
|
284 |
| - :rows="getTextareaRows(userPrompt, 1, 15)" |
| 284 | + @input="autoResizeUserPrompt" |
285 | 285 | 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"
|
286 | 286 | />
|
287 | 287 | </div>
|
@@ -328,6 +328,7 @@ import type { Model } from '~/types/response/models';
|
328 | 328 | import type { PromptCreateDTO, PromptUpdateDTO } from '~/types/components/prompt';
|
329 | 329 | import type { SchemaValidationResponse } from '~/types/response/schema';
|
330 | 330 | import { useDebounceFn } from '@vueuse/core';
|
| 331 | +import { ref, watch, computed, nextTick, onMounted } from 'vue'; |
331 | 332 |
|
332 | 333 | const props = defineProps<{
|
333 | 334 | prompt: Prompt | null
|
@@ -502,14 +503,42 @@ function selectModel(model: Model) {
|
502 | 503 | }
|
503 | 504 | }
|
504 | 505 |
|
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 | + }); |
511 | 528 | }
|
512 | 529 |
|
| 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 | +
|
513 | 542 |
|
514 | 543 | // Computed property for validation errors
|
515 | 544 | const validationErrors = computed(() => {
|
|
0 commit comments