diff --git a/package.json b/package.json index 6e2f5582..b2bbac6b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vocechat-web", - "version": "0.9.56", + "version": "0.9.57", "homepage": "https://voce.chat", "dependencies": { "@metamask/onboarding": "^1.0.1", diff --git a/src/components/Message/ContextMenu.tsx b/src/components/Message/ContextMenu.tsx index 657caee4..4d945d69 100644 --- a/src/components/Message/ContextMenu.tsx +++ b/src/components/Message/ContextMenu.tsx @@ -24,6 +24,7 @@ type Props = { hide: () => void; editMessage: () => void; children: ReactElement; + selectedText?: string; }; const MessageContextMenu: FC = ({ context, @@ -32,7 +33,8 @@ const MessageContextMenu: FC = ({ visible, hide, editMessage, - children + children, + selectedText = "" }) => { const { t } = useTranslation(); const { @@ -50,7 +52,7 @@ const MessageContextMenu: FC = ({ PinModal, ForwardModal, DeleteModal - } = useMessageOperation({ mid, contextId, context }); + } = useMessageOperation({ mid, contextId, context, selectedText }); const dispatch = useDispatch(); const { setReplying } = useSendMessage({ context, to: contextId }); const handleSelect = () => { diff --git a/src/components/Message/index.tsx b/src/components/Message/index.tsx index ce37aef1..8809f62c 100644 --- a/src/components/Message/index.tsx +++ b/src/components/Message/index.tsx @@ -42,6 +42,7 @@ const Message: FC = ({ const inViewRef = useInView(); const [edit, setEdit] = useState(false); const avatarRef = useRef(null); + const selectedTextRef = useRef(""); const { getPinInfo } = usePinMessage(context == "channel" ? contextId : 0); const message = useAppSelector((store) => store.message[mid], shallowEqual); const enableRightLayout = useAppSelector( @@ -104,7 +105,12 @@ const Message: FC = ({ return (
{ + // 在右键点击时保存选中的文本 + const selection = window.getSelection(); + selectedTextRef.current = selection?.toString().trim() || ""; + handleContextMenuEvent(evt); + }} data-msg-mid={mid} ref={inViewRef} className={clsx( @@ -141,6 +147,7 @@ const Message: FC = ({ mid={mid} visible={contextMenuVisible && !failed} hide={hideContextMenu} + selectedText={selectedTextRef.current} >
store.message[mid], shallowEqual); const loginUser = useAppSelector((store) => store.authData.user, shallowEqual); @@ -46,7 +47,12 @@ export default function useMessageOperation({ mid, context, contextId }: Params) setPinModalVisible((prev) => !prev); }; const copyContent = (image = false) => { - copy(content, image); + // 如果有选中的文本,复制选中的文本;否则复制整条消息 + if (selectedText && !image) { + copy(selectedText, false); + } else { + copy(content, image); + } }; useEffect(() => { if (forwardModalVisible && content_type == ContentTypes.archive) {