Skip to content

Commit

Permalink
fix: markdown editor save in mac error
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanyxh committed Jul 24, 2024
1 parent facafc8 commit c307679
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions src/filehandle/md_editor/component/MDEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ const blockElementKeys = [

const blockClass = { class: styles.typography };

const isMac = (() => {
const agent = navigator.userAgent.toLowerCase();
const isMac = /macintosh|mac os x/i.test(navigator.userAgent);
if (agent.indexOf('win32') >= 0 || agent.indexOf('wow32') >= 0) {
return false;
}
if (agent.indexOf('win64') >= 0 || agent.indexOf('wow64') >= 0) {
return false;
}
if (isMac) {
return true;
}

return false;
})();

const getMDString = getMarkdown();

let uploadInfo: UploadInfo | null = null;
Expand Down Expand Up @@ -203,10 +219,18 @@ const MDEditor = forwardRef<IMDEditorExpose, IMDEditorProps>(function MDEditor(p
}

const handleSave = (e: React.KeyboardEvent<HTMLDivElement>) => {
if (e.ctrlKey && e.key.toLocaleLowerCase() === 's') {
e.preventDefault();

changed && onSave(mdStringRef.current);
if (isMac) {
if (e.metaKey && e.key.toLocaleLowerCase() === 's') {
e.preventDefault();

changed && onSave(mdStringRef.current);
}
} else {
if (e.ctrlKey && e.key.toLocaleLowerCase() === 's') {
e.preventDefault();

changed && onSave(mdStringRef.current);
}
}
};

Expand Down

0 comments on commit c307679

Please sign in to comment.