1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Desktop, Mobile: Resolves #5593: Enable safe mode for Markdown editor too

This commit is contained in:
Laurent Cozic 2021-10-30 17:51:19 +01:00
parent aa3cbbd165
commit 0b01b5b0ef
4 changed files with 21 additions and 3 deletions

View File

@ -812,6 +812,7 @@ function CodeMirror(props: NoteBodyEditorProps, ref: any) {
onChange={codeMirror_change}
onScroll={editor_scroll}
onEditorPaste={onEditorPaste}
isSafeMode={props.isSafeMode}
/>
</div>
);

View File

@ -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<string, any> = {
value: props.value,
};
const unsafeOptions: Record<string, any> = {
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<string, any> = { ...safeOptions };
if (!props.isSafeMode) {
cmOptions = {
...cmOptions,
...unsafeOptions,
...userOptions,
};
}
const cm = CodeMirror(editorParent.current, cmOptions);
setEditor(cm);

View File

@ -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,
};
};

View File

@ -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 {