Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui-markdown-editor): handle cut image operation - #294 #298

Merged
merged 1 commit into from
Mar 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' });
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@irmerk @DianaLease @dselman Is this the best way to detect if the operation applies to an 'image'?

Copy link
Contributor Author

@Cronus1007 Cronus1007 Mar 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@irmerk @DianaLease @dselman Also tell me the best way to detect textnode.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have precedent here for detecting an image, see L175 under handleDrop in this file.

I'd look for other inspiration on a text node.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@irmerk Sure.


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

if (cut && imageNode) {
irmerk marked this conversation as resolved.
Show resolved Hide resolved
Editor.deleteBackward(editor);
}

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