Skip to content

Commit

Permalink
Desktop, Mobile: Resolves laurent22#5593: Enable safe mode for Markdo…
Browse files Browse the repository at this point in the history
…wn editor too
  • Loading branch information
laurent22 committed Oct 30, 2021
1 parent aa3cbbd commit 0b01b5b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@ function CodeMirror(props: NoteBodyEditorProps, ref: any) {
onChange={codeMirror_change}
onScroll={editor_scroll}
onEditorPaste={onEditorPaste}
isSafeMode={props.isSafeMode}
/>
</div>
);
Expand Down
19 changes: 16 additions & 3 deletions packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export interface EditorProps {
onChange: any;
onScroll: any;
onEditorPaste: any;
isSafeMode: boolean;
}

function Editor(props: EditorProps, ref: any) {
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions packages/app-desktop/gui/NoteEditor/NoteEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -611,6 +612,7 @@ const mapStateToProps = (state: AppState) => {
'setTags',
], whenClauseContext)[0],
contentMaxWidth: state.settings['style.editor.contentMaxWidth'],
isSafeMode: state.settings.isSafeMode,
};
};

Expand Down
2 changes: 2 additions & 0 deletions packages/app-desktop/gui/NoteEditor/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface NoteEditorProps {
setTagsToolbarButtonInfo: ToolbarButtonInfo;
richTextBannerDismissed: boolean;
contentMaxWidth: number;
isSafeMode: boolean;
}

export interface NoteBodyEditorProps {
Expand Down Expand Up @@ -74,6 +75,7 @@ export interface NoteBodyEditorProps {
plugins: PluginStates;
fontSize: number;
contentMaxWidth: number;
isSafeMode: boolean;
}

export interface FormNote {
Expand Down

0 comments on commit 0b01b5b

Please sign in to comment.