1
1
import { Box , Textarea } from '@invoke-ai/ui-library' ;
2
2
import { useAppDispatch , useAppSelector } from 'app/store/storeHooks' ;
3
+ import { usePersistedTextAreaSize } from 'common/hooks/usePersistedTextareaSize' ;
3
4
import { positivePromptChanged , selectBase , selectPositivePrompt } from 'features/controlLayers/store/paramsSlice' ;
4
5
import { ShowDynamicPromptsPreviewButton } from 'features/dynamicPrompts/components/ShowDynamicPromptsPreviewButton' ;
5
6
import { PromptLabel } from 'features/parameters/components/Prompts/PromptLabel' ;
@@ -14,20 +15,26 @@ import {
14
15
selectStylePresetViewMode ,
15
16
} from 'features/stylePresets/store/stylePresetSlice' ;
16
17
import { useRegisteredHotkeys } from 'features/system/components/HotkeysModal/useHotkeyData' ;
17
- import { positivePromptBoxHeightChanged , selectPositivePromptBoxHeight } from 'features/ui/store/uiSlice' ;
18
- import { debounce } from 'lodash-es' ;
19
- import { memo , useCallback , useEffect , useRef } from 'react' ;
18
+ import { memo , useCallback , useRef } from 'react' ;
20
19
import type { HotkeyCallback } from 'react-hotkeys-hook' ;
21
20
import { useTranslation } from 'react-i18next' ;
22
21
import { useListStylePresetsQuery } from 'services/api/endpoints/stylePresets' ;
23
22
23
+ const persistOptions : Parameters < typeof usePersistedTextAreaSize > [ 2 ] = {
24
+ trackWidth : false ,
25
+ trackHeight : true ,
26
+ initialHeight : 120 ,
27
+ } ;
28
+
24
29
export const ParamPositivePrompt = memo ( ( ) => {
25
30
const dispatch = useAppDispatch ( ) ;
26
31
const prompt = useAppSelector ( selectPositivePrompt ) ;
27
32
const baseModel = useAppSelector ( selectBase ) ;
28
33
const viewMode = useAppSelector ( selectStylePresetViewMode ) ;
29
34
const activeStylePresetId = useAppSelector ( selectStylePresetActivePresetId ) ;
30
- const positivePromptBoxHeight = useAppSelector ( selectPositivePromptBoxHeight ) ;
35
+
36
+ const textareaRef = useRef < HTMLTextAreaElement > ( null ) ;
37
+ usePersistedTextAreaSize ( 'positive_prompt' , textareaRef , persistOptions ) ;
31
38
32
39
const { activeStylePreset } = useListStylePresetsQuery ( undefined , {
33
40
selectFromResult : ( { data } ) => {
@@ -39,7 +46,6 @@ export const ParamPositivePrompt = memo(() => {
39
46
} ,
40
47
} ) ;
41
48
42
- const textareaRef = useRef < HTMLTextAreaElement > ( null ) ;
43
49
const { t } = useTranslation ( ) ;
44
50
const handleChange = useCallback (
45
51
( v : string ) => {
@@ -53,45 +59,6 @@ export const ParamPositivePrompt = memo(() => {
53
59
onChange : handleChange ,
54
60
} ) ;
55
61
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
-
95
62
const focus : HotkeyCallback = useCallback (
96
63
( e ) => {
97
64
onFocus ( ) ;
@@ -125,6 +92,7 @@ export const ParamPositivePrompt = memo(() => {
125
92
paddingTop = { 0 }
126
93
paddingBottom = { 3 }
127
94
resize = "vertical"
95
+ minH = { 28 }
128
96
/>
129
97
< PromptOverlayButtonWrapper >
130
98
< AddPromptTriggerButton isOpen = { isOpen } onOpen = { onOpen } />
0 commit comments