@@ -32,7 +32,7 @@ const adjustTextareaHeight = (textarea: HTMLTextAreaElement | null) => {
3232} ;
3333
3434// Interface describing the API returned by the hook
35- export interface AutosizeTextareaApi {
35+ export interface chatTextareaApi {
3636 value : ( ) => string ;
3737 setValue : ( value : string ) => void ;
3838 focus : ( ) => void ;
@@ -43,7 +43,7 @@ export interface AutosizeTextareaApi {
4343// This is a workaround to prevent the textarea from re-rendering when the inner content changes
4444// See https://github.com/ggml-org/llama.cpp/pull/12299
4545// combined now with auto-sizing logic.
46- export function useChatTextarea ( initValue : string ) : AutosizeTextareaApi {
46+ export function useChatTextarea ( initValue : string ) : chatTextareaApi {
4747 const [ savedInitValue , setSavedInitValue ] = useState < string > ( initValue ) ;
4848 const textareaRef = useRef < HTMLTextAreaElement > ( null ) ;
4949
@@ -63,10 +63,13 @@ export function useChatTextarea(initValue: string): AutosizeTextareaApi {
6363 }
6464 } , [ textareaRef , savedInitValue ] ) ; // Depend on ref and savedInitValue
6565
66- const handleInput = useCallback ( ( event : React . FormEvent < HTMLTextAreaElement > ) => {
67- // Call adjustTextareaHeight on every input - it will decide whether to act
68- adjustTextareaHeight ( event . currentTarget ) ;
69- } , [ ] ) ;
66+ const handleInput = useCallback (
67+ ( event : React . FormEvent < HTMLTextAreaElement > ) => {
68+ // Call adjustTextareaHeight on every input - it will decide whether to act
69+ adjustTextareaHeight ( event . currentTarget ) ;
70+ } ,
71+ [ ]
72+ ) ;
7073
7174 return {
7275 // Method to get the current value directly from the textarea
@@ -75,12 +78,12 @@ export function useChatTextarea(initValue: string): AutosizeTextareaApi {
7578 } ,
7679 // Method to programmatically set the value and trigger height adjustment
7780 setValue : ( value : string ) => {
78- const textarea = textareaRef . current ;
79- if ( textarea ) {
80- textarea . value = value ;
81- // Call adjustTextareaHeight - it will check screen size internally
82- setTimeout ( ( ) => adjustTextareaHeight ( textarea ) , 0 ) ;
83- }
81+ const textarea = textareaRef . current ;
82+ if ( textarea ) {
83+ textarea . value = value ;
84+ // Call adjustTextareaHeight - it will check screen size internally
85+ setTimeout ( ( ) => adjustTextareaHeight ( textarea ) , 0 ) ;
86+ }
8487 } ,
8588 focus : ( ) => {
8689 if ( textareaRef . current ) {
@@ -90,4 +93,4 @@ export function useChatTextarea(initValue: string): AutosizeTextareaApi {
9093 ref : textareaRef ,
9194 onInput : handleInput ,
9295 } ;
93- }
96+ }
0 commit comments