fix: paste text can not overwrite the selection

This commit is contained in:
jialin
2025-01-15 16:11:57 +08:00
parent 5bfca0f86f
commit 53a4ebb66e
7 changed files with 94 additions and 56 deletions
+1 -1
View File
@@ -24,7 +24,7 @@
display: flex;
justify-content: center;
align-items: center;
background-color: var(--ant-color-fill-secondary);
background-color: rgba(0, 0, 0, 30%);
.ant-progress-text {
color: var(--color-white-secondary);
+11 -13
View File
@@ -490,22 +490,20 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
await drawImage();
setImgLoaded(true);
console.log('Image Loaded:', imageStatus, strokesRef.current);
// if (strokeCache.current[imguid]) {
// strokesRef.current = strokeCache.current[imguid];
// } else if (preImguid.current !== imguid) {
// strokeCache.current[preImguid.current] = strokesRef.current;
// onReset();
// resetCanvas();
// preImguid.current = imguid;
// }
if (imageStatus.isOriginal) {
redrawStrokes(strokesRef.current, 'initialize');
} else if (imageStatus.isResetNeeded) {
if (strokeCache.current[imguid]) {
strokeCache.current[preImguid.current] = strokesRef.current;
strokesRef.current = strokeCache.current[imguid];
} else if (preImguid.current !== imguid) {
strokeCache.current[preImguid.current] = strokesRef.current;
onReset();
resetCanvas();
}
}, [drawImage, onReset, redrawStrokes, imageStatus]);
preImguid.current = imguid;
if (strokesRef.current.length) {
redrawStrokes(strokesRef.current);
}
}, [drawImage, onReset, redrawStrokes, imguid, imageStatus]);
const updateZoom = (scaleChange: number, mouseX: number, mouseY: number) => {
const newScale = _.round(autoScale.current + scaleChange, 2);
+31 -1
View File
@@ -13,10 +13,24 @@ interface SystemMessageProps {
height?: number;
onChange: (e: any) => void;
onPaste?: (e: any) => void;
onSelect?: (data: {
start: number;
end: number;
beforeText: string;
afterText: string;
}) => void;
}
const RowTextarea: React.FC<SystemMessageProps> = (props) => {
const { value, onChange, style, label, placeholder, height = 46 } = props;
const {
value,
onChange,
onSelect,
style,
label,
placeholder,
height = 46
} = props;
const intl = useIntl();
const rowTextAreaRef = React.useRef<any>(null);
const [autoSize, setAutoSize] = useState<{
@@ -57,6 +71,21 @@ const RowTextarea: React.FC<SystemMessageProps> = (props) => {
props.onPaste?.(e);
};
const handleOnSelect = (e: any) => {
e.stopPropagation();
const start = e.target.selectionStart;
const end = e.target.selectionEnd;
const beforeText = value.substring(0, start);
const afterText = value.substring(end, value.length);
onSelect?.({
start,
end,
beforeText,
afterText
});
};
return (
<div
className={classNames('row-textarea', {
@@ -87,6 +116,7 @@ const RowTextarea: React.FC<SystemMessageProps> = (props) => {
onBlur={handleBlur}
allowClear={false}
onChange={handleOnChange}
onSelect={handleOnSelect}
onPaste={handleOnPaste}
></Input.TextArea>
</div>