Skip to content

Commit

Permalink
fix: disable "Auto translate after input in input box" will not send …
Browse files Browse the repository at this point in the history
…translate requests after you use "Ctrl + Enter" in input box
  • Loading branch information
chunibyocola committed Jul 5, 2021
1 parent f610545 commit 4c81693
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions src/components/RawText/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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'
></textarea>
Expand Down

0 comments on commit 4c81693

Please sign in to comment.