@@ -14,7 +14,9 @@ import {
1414 selectStylePresetViewMode ,
1515} from 'features/stylePresets/store/stylePresetSlice' ;
1616import { useRegisteredHotkeys } from 'features/system/components/HotkeysModal/useHotkeyData' ;
17- import { memo , useCallback , useRef } from 'react' ;
17+ import { positivePromptBoxHeightChanged , selectPositivePromptBoxHeight } from 'features/ui/store/uiSlice' ;
18+ import { debounce } from 'lodash-es' ;
19+ import { memo , useCallback , useEffect , useRef } from 'react' ;
1820import type { HotkeyCallback } from 'react-hotkeys-hook' ;
1921import { useTranslation } from 'react-i18next' ;
2022import { useListStylePresetsQuery } from 'services/api/endpoints/stylePresets' ;
@@ -25,6 +27,7 @@ export const ParamPositivePrompt = memo(() => {
2527 const baseModel = useAppSelector ( selectBase ) ;
2628 const viewMode = useAppSelector ( selectStylePresetViewMode ) ;
2729 const activeStylePresetId = useAppSelector ( selectStylePresetActivePresetId ) ;
30+ const positivePromptBoxHeight = useAppSelector ( selectPositivePromptBoxHeight ) ;
2831
2932 const { activeStylePreset } = useListStylePresetsQuery ( undefined , {
3033 selectFromResult : ( { data } ) => {
@@ -50,6 +53,45 @@ export const ParamPositivePrompt = memo(() => {
5053 onChange : handleChange ,
5154 } ) ;
5255
56+ // Add debounced resize observer to detect height changes
57+ useEffect ( ( ) => {
58+ const textarea = textareaRef . current ;
59+ if ( ! textarea ) {
60+ return ;
61+ }
62+
63+ let currentHeight = textarea . offsetHeight ;
64+
65+ const debouncedHeightUpdate = debounce ( ( newHeight : number ) => {
66+ dispatch ( positivePromptBoxHeightChanged ( newHeight ) ) ;
67+ } , 150 ) ;
68+
69+ const resizeObserver = new ResizeObserver ( ( entries ) => {
70+ for ( const entry of entries ) {
71+ const newHeight = ( entry . target as HTMLTextAreaElement ) . offsetHeight ;
72+ if ( newHeight !== currentHeight ) {
73+ currentHeight = newHeight ;
74+ debouncedHeightUpdate ( newHeight ) ;
75+ }
76+ }
77+ } ) ;
78+
79+ resizeObserver . observe ( textarea ) ;
80+ return ( ) => {
81+ resizeObserver . disconnect ( ) ;
82+ debouncedHeightUpdate . cancel ( ) ;
83+ } ;
84+ } , [ dispatch ] ) ;
85+
86+ useEffect ( ( ) => {
87+ const textarea = textareaRef . current ;
88+ if ( ! textarea ) {
89+ return ;
90+ }
91+
92+ textarea . style . height = `${ positivePromptBoxHeight } px` ;
93+ } , [ positivePromptBoxHeight ] ) ;
94+
5395 const focus : HotkeyCallback = useCallback (
5496 ( e ) => {
5597 onFocus ( ) ;
@@ -75,14 +117,14 @@ export const ParamPositivePrompt = memo(() => {
75117 ref = { textareaRef }
76118 value = { prompt }
77119 onChange = { onChange }
78- minH = { 40 }
79120 onKeyDown = { onKeyDown }
80121 variant = "darkFilled"
81122 borderTopWidth = { 24 } // This prevents the prompt from being hidden behind the header
82123 paddingInlineEnd = { 10 }
83124 paddingInlineStart = { 3 }
84125 paddingTop = { 0 }
85126 paddingBottom = { 3 }
127+ resize = "vertical"
86128 />
87129 < PromptOverlayButtonWrapper >
88130 < AddPromptTriggerButton isOpen = { isOpen } onOpen = { onOpen } />
0 commit comments