From 8f44059f52db29dd6ef970533bf29a33d30e6b71 Mon Sep 17 00:00:00 2001 From: Tristan Yang Date: Fri, 12 Aug 2022 21:44:04 +0800 Subject: [PATCH] fix: enter new line sometimes --- src/common/component/MixedInput/index.tsx | 30 ++++++----------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/src/common/component/MixedInput/index.tsx b/src/common/component/MixedInput/index.tsx index edbd21fe..929f3838 100644 --- a/src/common/component/MixedInput/index.tsx +++ b/src/common/component/MixedInput/index.tsx @@ -48,12 +48,11 @@ const Plugins: FC = ({ members = [] }) => { // const { getMenuProps, getItemProps } = useComboboxControls(); - const [context, to] = id.split("_"); - const { addStageFile } = useUploadFile({ context, id: Number(to) }); + const [context, to] = id.split("_") as [ctx, number]; + const { addStageFile } = useUploadFile({ context, id: to }); const enableMentions = members.length > 0; const userData = useAppSelector((store) => store.users.byId); const [msgs, setMsgs] = useState([]); - const [cmdKey, setCmdKey] = useState(false); const editableRef = useRef(null); const initialProps = { ...CONFIG.editableProps, @@ -67,13 +66,10 @@ const Plugins: FC = ({ if (files.length) { const filesData = files.map((file) => { const { size, type, name } = file; - console.log("paste event name", name); + // console.log("paste event name", name); const url = URL.createObjectURL(file); return { size, type, name, url }; }); - const [context, to] = id.split("_"); - - console.log("paste event", context, to, files, evt); addStageFile(filesData); } }; @@ -90,9 +86,11 @@ const Plugins: FC = ({ useKey( "Enter", (evt) => { + // console.log("tttt", plateEditor); if (!plateEditor) return; // 是否在at操作 const mentionInputs = findMentionInput(plateEditor); + // console.log("tttt", mentionInputs, evt); if (mentionInputs || evt.shiftKey || evt.ctrlKey || evt.altKey || evt.isComposing) { return true; } @@ -108,18 +106,6 @@ const Plugins: FC = ({ }); }, { - target: editableRef, - when: !cmdKey - } - ); - useKey( - [91, 93], - (evt) => { - setCmdKey(evt.type == "keydown"); - console.log("cmd", evt.type); - }, - { - eventTypes: ["keydown", "keyup"], target: editableRef } ); @@ -137,7 +123,7 @@ const Plugins: FC = ({ createMentionPlugin({ options: { createMentionNode: (item) => { - console.log("mention", item); + // console.log("mention", item); const { text, data: { uid } @@ -200,7 +186,7 @@ const Plugins: FC = ({ }); const msgs = arr.filter(({ content }) => !!content); setMsgs(msgs); - console.log("tmps", tmps, arr, msgs); + // console.log("tmps", tmps, arr, msgs); }, [msgs] ); @@ -251,7 +237,7 @@ export const useMixedEditor = (key: string) => { } }; const insertText = (txt: string) => { - console.log("eref", editorRef); + // console.log("eref", editorRef); if (editorRef) { ReactEditor.focus(editorRef); editorRef.insertText(txt);