From 9f1f62b9be4d70f59717910ae4c20f98d65d0577 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Mon, 12 Dec 2022 11:17:41 +0000 Subject: [PATCH] Add rich-text mode to CM6 (#10775) Co-Authored-By: Mathias Jakobsen <3295293+hrjakobsen@users.noreply.github.com> GitOrigin-RevId: 00e015cb216bb8a52d083e71b34dbe91a7cd6cc5 --- .../components/editor-switch.tsx | 25 +++++++++++++++---- .../frontend/js/ide/editor/EditorManager.js | 18 +++++++++++++ .../js/ide/file-tree/FileTreeManager.js | 7 ++++++ .../stylesheets/app/editor/toolbar.less | 7 ++++++ services/web/types/window.ts | 3 +++ 5 files changed, 55 insertions(+), 5 deletions(-) diff --git a/services/web/frontend/js/features/source-editor/components/editor-switch.tsx b/services/web/frontend/js/features/source-editor/components/editor-switch.tsx index cf0ee45859..6fbfa27c54 100644 --- a/services/web/frontend/js/features/source-editor/components/editor-switch.tsx +++ b/services/web/frontend/js/features/source-editor/components/editor-switch.tsx @@ -3,6 +3,8 @@ import useScopeValue from '../../../shared/hooks/use-scope-value' import Tooltip from '../../../shared/components/tooltip' import { sendMB } from '../../../infrastructure/event-tracking' +const params = new URLSearchParams(window.location.search) + function Badge() { const content = ( <> @@ -42,6 +44,10 @@ function EditorSwitch() { ) const [richText, setRichText] = useScopeValue('editor.showRichText') + const [visual, setVisual] = useScopeValue('editor.showVisual') + + const richTextOrVisual = richText || visual + const handleChange = useCallback( event => { const editorType = event.target.value @@ -49,22 +55,31 @@ function EditorSwitch() { switch (editorType) { case 'ace': setRichText(false) + setVisual(false) setNewSourceEditor(false) break case 'cm6': setRichText(false) + setVisual(false) setNewSourceEditor(true) break case 'rich-text': - setRichText(true) + if (params.has('cm_visual')) { + setRichText(false) + setVisual(true) + setNewSourceEditor(true) + } else { + setRichText(true) + setVisual(false) + } break } sendMB('editor-switch-change', { editorType }) }, - [setRichText, setNewSourceEditor] + [setRichText, setVisual, setNewSourceEditor] ) return ( @@ -80,7 +95,7 @@ function EditorSwitch() { value="cm6" id="editor-switch-cm6" className="toggle-switch-input" - checked={!richText && !!newSourceEditor} + checked={!richTextOrVisual && !!newSourceEditor} onChange={handleChange} />