Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions src/components/TextareaComposer/TextareaComposer.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import debounce from 'lodash.debounce';
import clsx from 'clsx';
import type {
ChangeEventHandler,
SyntheticEvent,
TextareaHTMLAttributes,
UIEventHandler,
} from 'react';
import { useMemo } from 'react';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import Textarea from 'react-textarea-autosize';
import { useMessageComposer } from '../MessageInput';
Expand Down Expand Up @@ -209,19 +207,14 @@
[onScroll, textComposer],
);

const setSelectionDebounced = useMemo(
() =>
debounce(
(e: SyntheticEvent<HTMLTextAreaElement>) => {
onSelect?.(e);
textComposer.setSelection({
end: (e.target as HTMLTextAreaElement).selectionEnd,
start: (e.target as HTMLTextAreaElement).selectionStart,
});
},
100,
{ leading: false, trailing: true },
),
const setSelectionDebounced = useCallback(
(e: SyntheticEvent<HTMLTextAreaElement>) => {
onSelect?.(e);
textComposer.setSelection({

Check warning on line 213 in src/components/TextareaComposer/TextareaComposer.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/TextareaComposer/TextareaComposer.tsx#L212-L213

Added lines #L212 - L213 were not covered by tests
end: (e.target as HTMLTextAreaElement).selectionEnd,
start: (e.target as HTMLTextAreaElement).selectionStart,
});
},
[onSelect, textComposer],
);

Expand Down