Skip to content

Commit

Permalink
feat(ui-markdown-editor): cut image operation
Browse files Browse the repository at this point in the history
Signed-off-by: Cronus1007 <lit2019058@iiitl.ac.in>
  • Loading branch information
Cronus1007 committed Mar 12, 2021
1 parent 90973d4 commit 5abf561
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 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, BLOCK_STYLE } 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 All @@ -37,7 +36,7 @@ export const MarkdownEditor = (props) => {
canBeFormatted
} = props;
const [showLinkModal, setShowLinkModal] = useState(false);
const [currentStyle, setCurrentStyle] = useState('')
const [currentStyle, setCurrentStyle] = useState('');
const editor = useMemo(() => {
if (augmentEditor) {
return augmentEditor(
Expand Down Expand Up @@ -91,7 +90,7 @@ export const MarkdownEditor = (props) => {
return;
}

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

Expand Down Expand Up @@ -130,10 +129,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 5abf561

Please sign in to comment.