From d9910822df6dbaf23fbb8636f2234e96d03e9cab Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Mon, 7 Nov 2022 14:25:29 +0000 Subject: [PATCH] Merge pull request #10339 from overleaf/as-fix-switch-back Fix bug in CM6 switch away survey where going back from Ace to CM6 will still show the survey GitOrigin-RevId: 5900fafb1a4a5fab7d949b1c70af31e19a764e6e --- .../components/cm6-switch-away-survey.tsx | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/services/web/frontend/js/features/source-editor/components/cm6-switch-away-survey.tsx b/services/web/frontend/js/features/source-editor/components/cm6-switch-away-survey.tsx index a7b72d67cc..d8b2ba9365 100644 --- a/services/web/frontend/js/features/source-editor/components/cm6-switch-away-survey.tsx +++ b/services/web/frontend/js/features/source-editor/components/cm6-switch-away-survey.tsx @@ -36,29 +36,33 @@ export default function CM6SwitchAwaySurvey() { return } - if (!newSourceEditor) { + if (!newSourceEditor && !richText) { setState('enabled') + } else { + setState('disabled') } }, [newSourceEditor, richText]) useEffect(() => { - if (state === 'enabled') { - const handleKeyDown = () => { - const TIME_FOR_SURVEY_TO_APPEAR = 3000 + const handleKeyDown = () => { + const TIME_FOR_SURVEY_TO_APPEAR = 3000 - setTimeout(() => { + setTimeout(() => { + if (state === 'enabled') { setState('shown') customLocalStorage.setItem( 'editor.has_seen_cm6_switch_away_survey', true ) - }, TIME_FOR_SURVEY_TO_APPEAR) - } - - // can't access the ace editor directly, so add the keydown event - // to window - window?.addEventListener('keydown', handleKeyDown, { once: true }) + } + }, TIME_FOR_SURVEY_TO_APPEAR) } + + // can't access the ace editor directly, so add the keydown event + // to window + window?.addEventListener('keydown', handleKeyDown, { once: true }) + + return () => window?.removeEventListener('keydown', handleKeyDown) }, [state]) const handleClose = useCallback(() => {