fix: paste text can not overwrite the selection
This commit is contained in:
@@ -85,6 +85,7 @@ const GroundEmbedding: React.FC<MessageProps> = forwardRef((props, ref) => {
|
||||
});
|
||||
const [lessTwoInput, setLessTwoInput] = useState<boolean>(false);
|
||||
const multiplePasteEnable = useRef<boolean>(true);
|
||||
const selectionTextRef = useRef<any>(null);
|
||||
|
||||
const [textList, setTextList] = useState<
|
||||
{ text: string; uid: number | string; name: string }[]
|
||||
@@ -303,6 +304,19 @@ const GroundEmbedding: React.FC<MessageProps> = forwardRef((props, ref) => {
|
||||
setTextList(list);
|
||||
};
|
||||
|
||||
const handleonSelect = useCallback(
|
||||
(data: {
|
||||
start: number;
|
||||
end: number;
|
||||
beforeText: string;
|
||||
afterText: string;
|
||||
index: number;
|
||||
}) => {
|
||||
selectionTextRef.current = data;
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
const handleOnPaste = useCallback(
|
||||
(e: any, index: number) => {
|
||||
if (!multiplePasteEnable.current) return;
|
||||
@@ -316,7 +330,7 @@ const GroundEmbedding: React.FC<MessageProps> = forwardRef((props, ref) => {
|
||||
name: ''
|
||||
};
|
||||
});
|
||||
dataLlist[0].text = currentContent + dataLlist[0].text;
|
||||
dataLlist[0].text = `${selectionTextRef.current?.beforeText || ''}${dataLlist[0].text}${selectionTextRef.current?.afterText || ''}`;
|
||||
const result = [
|
||||
...textList.slice(0, index),
|
||||
...dataLlist,
|
||||
@@ -527,6 +541,7 @@ const GroundEmbedding: React.FC<MessageProps> = forwardRef((props, ref) => {
|
||||
ref={inputListRef}
|
||||
textList={textList}
|
||||
onChange={handleTextListChange}
|
||||
onSelect={handleonSelect}
|
||||
onPaste={handleOnPaste}
|
||||
></InputList>
|
||||
<div style={{ marginTop: 8 }}>
|
||||
|
||||
@@ -124,6 +124,7 @@ const GroundReranker: React.FC<MessageProps> = forwardRef((props, ref) => {
|
||||
]);
|
||||
const [sortIndexMap, setSortIndexMap] = useState<number[]>([]);
|
||||
const [queryValue, setQueryValue] = useState<string>('');
|
||||
const selectionTextRef = useRef<any>(null);
|
||||
|
||||
const { initialize, updateScrollerPosition: updateDocumentScrollerPosition } =
|
||||
useOverlayScroller();
|
||||
@@ -364,6 +365,19 @@ const GroundReranker: React.FC<MessageProps> = forwardRef((props, ref) => {
|
||||
[]
|
||||
);
|
||||
|
||||
const handleonSelect = useCallback(
|
||||
(data: {
|
||||
start: number;
|
||||
end: number;
|
||||
beforeText: string;
|
||||
afterText: string;
|
||||
index: number;
|
||||
}) => {
|
||||
selectionTextRef.current = data;
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
const handleOnPaste = useCallback(
|
||||
(e: any, index: number) => {
|
||||
if (!multiplePasteEnable.current) return;
|
||||
@@ -377,7 +391,7 @@ const GroundReranker: React.FC<MessageProps> = forwardRef((props, ref) => {
|
||||
name: ''
|
||||
};
|
||||
});
|
||||
dataLlist[0].text = currentContent + dataLlist[0].text;
|
||||
dataLlist[0].text = `${selectionTextRef.current?.beforeText || ''}${dataLlist[0].text}${selectionTextRef.current?.afterText || ''}`;
|
||||
const result = [
|
||||
...textList.slice(0, index),
|
||||
...dataLlist,
|
||||
|
||||
@@ -31,6 +31,12 @@ interface InputListProps {
|
||||
onSort?: (
|
||||
textList: { text: string; uid: number | string; name: string }[]
|
||||
) => void;
|
||||
onSelect?: (data: {
|
||||
start: number;
|
||||
end: number;
|
||||
beforeText: string;
|
||||
afterText: string;
|
||||
}) => void;
|
||||
}
|
||||
|
||||
const InputList: React.FC<InputListProps> = forwardRef(
|
||||
@@ -44,7 +50,8 @@ const InputList: React.FC<InputListProps> = forwardRef(
|
||||
onSort,
|
||||
onChange,
|
||||
extra,
|
||||
onPaste
|
||||
onPaste,
|
||||
onSelect
|
||||
},
|
||||
ref
|
||||
) => {
|
||||
@@ -244,6 +251,7 @@ const InputList: React.FC<InputListProps> = forwardRef(
|
||||
})}
|
||||
onChange={(e) => handleTextChange(e.target.value, text)}
|
||||
onPaste={(e) => onPaste?.(e, index)}
|
||||
onSelect={(data) => onSelect?.({ ...data, index })}
|
||||
></RowTextarea>
|
||||
</div>
|
||||
<span className="btn-group">
|
||||
|
||||
Reference in New Issue
Block a user