From 0b01b5b0ef7a2e9ac9e96a53b85bdf44e14d2f18 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sat, 30 Oct 2021 17:51:19 +0100 Subject: [PATCH] Desktop, Mobile: Resolves #5593: Enable safe mode for Markdown editor too --- .../NoteBody/CodeMirror/CodeMirror.tsx | 1 + .../NoteEditor/NoteBody/CodeMirror/Editor.tsx | 19 ++++++++++++++++--- .../app-desktop/gui/NoteEditor/NoteEditor.tsx | 2 ++ .../app-desktop/gui/NoteEditor/utils/types.ts | 2 ++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/CodeMirror.tsx b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/CodeMirror.tsx index edb28bfa39e..7a153e319f7 100644 --- a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/CodeMirror.tsx +++ b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/CodeMirror.tsx @@ -812,6 +812,7 @@ function CodeMirror(props: NoteBodyEditorProps, ref: any) { onChange={codeMirror_change} onScroll={editor_scroll} onEditorPaste={onEditorPaste} + isSafeMode={props.isSafeMode} /> ); diff --git a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/Editor.tsx b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/Editor.tsx index 4d6fa64a44d..e423a46a5e9 100644 --- a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/Editor.tsx +++ b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/Editor.tsx @@ -92,6 +92,7 @@ export interface EditorProps { onChange: any; onScroll: any; onEditorPaste: any; + isSafeMode: boolean; } function Editor(props: EditorProps, ref: any) { @@ -149,11 +150,13 @@ function Editor(props: EditorProps, ref: any) { useEffect(() => { if (!editorParent.current) return () => {}; - // const userOptions = eventManager.filterEmit('codeMirrorOptions', {}); const userOptions = {}; - const cmOptions = Object.assign({}, { + const safeOptions: Record = { value: props.value, + }; + + const unsafeOptions: Record = { screenReaderLabel: props.value, theme: props.codeMirrorTheme, mode: props.mode, @@ -167,7 +170,17 @@ function Editor(props: EditorProps, ref: any) { spellcheck: true, allowDropFileTypes: [''], // disable codemirror drop handling keyMap: props.keyMap ? props.keyMap : 'default', - }, userOptions); + }; + + let cmOptions: Record = { ...safeOptions }; + + if (!props.isSafeMode) { + cmOptions = { + ...cmOptions, + ...unsafeOptions, + ...userOptions, + }; + } const cm = CodeMirror(editorParent.current, cmOptions); setEditor(cm); diff --git a/packages/app-desktop/gui/NoteEditor/NoteEditor.tsx b/packages/app-desktop/gui/NoteEditor/NoteEditor.tsx index 2b4942a17b4..645d0ae8339 100644 --- a/packages/app-desktop/gui/NoteEditor/NoteEditor.tsx +++ b/packages/app-desktop/gui/NoteEditor/NoteEditor.tsx @@ -409,6 +409,7 @@ function NoteEditor(props: NoteEditorProps) { plugins: props.plugins, fontSize: Setting.value('style.editor.fontSize'), contentMaxWidth: props.contentMaxWidth, + isSafeMode: props.isSafeMode, }; let editor = null; @@ -611,6 +612,7 @@ const mapStateToProps = (state: AppState) => { 'setTags', ], whenClauseContext)[0], contentMaxWidth: state.settings['style.editor.contentMaxWidth'], + isSafeMode: state.settings.isSafeMode, }; }; diff --git a/packages/app-desktop/gui/NoteEditor/utils/types.ts b/packages/app-desktop/gui/NoteEditor/utils/types.ts index 24d9c39b4b5..f42fb33f4c2 100644 --- a/packages/app-desktop/gui/NoteEditor/utils/types.ts +++ b/packages/app-desktop/gui/NoteEditor/utils/types.ts @@ -43,6 +43,7 @@ export interface NoteEditorProps { setTagsToolbarButtonInfo: ToolbarButtonInfo; richTextBannerDismissed: boolean; contentMaxWidth: number; + isSafeMode: boolean; } export interface NoteBodyEditorProps { @@ -74,6 +75,7 @@ export interface NoteBodyEditorProps { plugins: PluginStates; fontSize: number; contentMaxWidth: number; + isSafeMode: boolean; } export interface FormNote {