From 4c8169353f04a2292a85e99fa49648c2d5e2137f Mon Sep 17 00:00:00 2001 From: sweetcola <838689894@qq.com> Date: Mon, 5 Jul 2021 18:33:52 +0800 Subject: [PATCH] fix: disable "Auto translate after input in input box" will not send translate requests after you use "Ctrl + Enter" in input box --- src/components/RawText/index.js | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/components/RawText/index.js b/src/components/RawText/index.js index 93dd7496..6de6ac64 100644 --- a/src/components/RawText/index.js +++ b/src/components/RawText/index.js @@ -8,7 +8,6 @@ const RawText = ({ defaultValue, rawTextTranslate, focusDependency, autoTranslat const [debounceDependency, setDebounceDependency] = useState(0); const lastTextRef = useRef(''); - const stopPropagationRef = useRef(e => e.stopPropagation()); const textareaEl = useRef(null); const compositionStatus = useRef(false); @@ -41,16 +40,6 @@ const RawText = ({ defaultValue, rawTextTranslate, focusDependency, autoTranslat autoTranslateAfterInput && !compositionStatus.current && rawTextChanged(); }, [rawTextChanged, autoTranslateAfterInput]); - const onFocus = useCallback(() => { - window.addEventListener('keydown', stopPropagationRef.current, true); - window.addEventListener('keyup', stopPropagationRef.current, true); - }, []); - - const onBlur = useCallback(() => { - window.removeEventListener('keydown', stopPropagationRef.current, true); - window.removeEventListener('keyup', stopPropagationRef.current, true); - }, []); - useEffect(() => { if (defaultValue) { lastTextRef.current = defaultValue.trimRight(); @@ -86,8 +75,8 @@ const RawText = ({ defaultValue, rawTextTranslate, focusDependency, autoTranslat onChange={onChange} onCompositionStart={onCompositionStart} onCompositionEnd={onCompositionEnd} - onFocus={onFocus} - onBlur={onBlur} + onKeyDown={e => e.stopPropagation()} + onKeyUp={e => e.stopPropagation()} ref={textareaEl} className='ts-rt-text' >