Skip to content

Commit

Permalink
fix(ui-markdown-editor): handle cut image operation
Browse files Browse the repository at this point in the history
  • Loading branch information
Cronus1007 committed Mar 15, 2021
1 parent b6ccb71 commit df41853
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/ui-markdown-editor/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import { BUTTON_ACTIVE } from './utilities/constants';
import withSchema from './utilities/schema';
import Element from './components';
import Leaf from './components/Leaf';
import { toggleMark, toggleBlock, insertThematicBreak,
insertLinebreak, insertHeadingbreak, isBlockHeading
} from './utilities/toolbarHelpers';
import { toggleMark, toggleBlock, insertThematicBreak,
insertLinebreak, insertHeadingbreak, isBlockHeading } from './utilities/toolbarHelpers';
import { withImages, insertImage } from './plugins/withImages';
import { withLinks, isSelectionLinkBody } from './plugins/withLinks';
import { withHtml } from './plugins/withHtml';
Expand Down Expand Up @@ -90,7 +89,7 @@ export const MarkdownEditor = (props) => {
return;
}

if (event.key === "Enter" && !isBlockHeading(editor)) {
if (event.key === 'Enter' && !isBlockHeading(editor)) {
return;
}

Expand Down Expand Up @@ -129,10 +128,15 @@ export const MarkdownEditor = (props) => {
const CICERO_MARK_DOM = slateTransformer.toCiceroMark(SLATE_DOM);
const HTML_DOM = htmlTransformer.toHtml(CICERO_MARK_DOM);
const MARKDOWN_TEXT = ciceroMarkTransformer.toMarkdown(CICERO_MARK_DOM);
const [imageNode] = Editor.nodes(editor, { match: n => n.type === 'image' });

event.clipboardData.setData('text/html', HTML_DOM);
event.clipboardData.setData('text/plain', MARKDOWN_TEXT);

if (cut && imageNode) {
Editor.deleteBackward(editor);
}

if (cut && editor.selection && Range.isExpanded(editor.selection)) {
Editor.deleteFragment(editor);
}
Expand Down

0 comments on commit df41853

Please sign in to comment.