Skip to content

Commit e50d89a

Browse files
authored
fix: prevent debouncing the selection state update in TextareaComposer (#2741)
1 parent 0d021ee commit e50d89a

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

src/components/TextareaComposer/TextareaComposer.tsx

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import debounce from 'lodash.debounce';
21
import clsx from 'clsx';
32
import type {
43
ChangeEventHandler,
54
SyntheticEvent,
65
TextareaHTMLAttributes,
76
UIEventHandler,
87
} from 'react';
9-
import { useMemo } from 'react';
108
import React, { useCallback, useEffect, useRef, useState } from 'react';
119
import Textarea from 'react-textarea-autosize';
1210
import { useMessageComposer } from '../MessageInput';
@@ -209,19 +207,14 @@ export const TextareaComposer = ({
209207
[onScroll, textComposer],
210208
);
211209

212-
const setSelectionDebounced = useMemo(
213-
() =>
214-
debounce(
215-
(e: SyntheticEvent<HTMLTextAreaElement>) => {
216-
onSelect?.(e);
217-
textComposer.setSelection({
218-
end: (e.target as HTMLTextAreaElement).selectionEnd,
219-
start: (e.target as HTMLTextAreaElement).selectionStart,
220-
});
221-
},
222-
100,
223-
{ leading: false, trailing: true },
224-
),
210+
const setSelectionDebounced = useCallback(
211+
(e: SyntheticEvent<HTMLTextAreaElement>) => {
212+
onSelect?.(e);
213+
textComposer.setSelection({
214+
end: (e.target as HTMLTextAreaElement).selectionEnd,
215+
start: (e.target as HTMLTextAreaElement).selectionStart,
216+
});
217+
},
225218
[onSelect, textComposer],
226219
);
227220

0 commit comments

Comments
 (0)