From bbfd5a08dbcba4484777e1d85b707f608aa2cba9 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sun, 24 Sep 2023 15:24:19 +0800 Subject: [PATCH] refactor: change paste handler process order make sure image handler as fallback and can trigger in any time --- .../components/ChatBox/ChatInputBox/index.tsx | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/client/web/src/components/ChatBox/ChatInputBox/index.tsx b/client/web/src/components/ChatBox/ChatInputBox/index.tsx index 5f94b609..0c0a2ea5 100644 --- a/client/web/src/components/ChatBox/ChatInputBox/index.tsx +++ b/client/web/src/components/ChatBox/ChatInputBox/index.tsx @@ -68,16 +68,6 @@ export const ChatInputBox: React.FC = React.memo((props) => { (e: React.ClipboardEvent) => { const el: HTMLTextAreaElement | HTMLInputElement = e.currentTarget; const helper = new ClipboardHelper(e); - const image = helper.hasImage(); - if (image) { - // 上传图片 - e.preventDefault(); - uploadMessageImage(image).then(({ url, width, height }) => { - props.onSendMsg( - getMessageTextDecorators().image(url, { width, height }) - ); - }); - } if (!el.value) { // 当没有任何输入内容时才会执行handler @@ -88,8 +78,21 @@ export const ChatInputBox: React.FC = React.memo((props) => { sendMessage, applyMessage: setMessage, }); + return; } } + + // If not match any paste handler or not paste without any input, fallback to image paste checker + const image = helper.hasImage(); + if (image) { + // 上传图片 + e.preventDefault(); + uploadMessageImage(image).then(({ url, width, height }) => { + props.onSendMsg( + getMessageTextDecorators().image(url, { width, height }) + ); + }); + } } );