Skip to content

Commit

Permalink
Fix #25726 Block Editor: Copy - Paste Word Doc creates an image inste…
Browse files Browse the repository at this point in the history
…ad of a paragraph in Chrome and Mac
  • Loading branch information
rjvelazco committed Aug 10, 2023
1 parent 7c32d20 commit 45d94c3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
Expand Up @@ -191,31 +191,35 @@ export const AssetUploader = (injector: Injector, viewContainerRef: ViewContaine
function hanlderPaste(view: EditorView, event: ClipboardEvent) {
const { clipboardData } = event;
const { files } = clipboardData;
const { length } = files;
const file = files[0];
const text = clipboardData.getData('Text') || '';
const type = isImageURL(text) ? 'image' : (getFileType(file) as EditorAssetTypes);
const type = getFileType(files[0]) as EditorAssetTypes;
const isRegistered = isNodeRegistered(type);

const { from } = getCursorPosition(view);
if (type && !isRegistered) {
alertErrorMessage(type);

if (!isNodeRegistered(type)) {
return;
}

if (length > 1) {
alertErrorMessage(type);

// If the text is not an image URL, we don't want to prevent the default behavior.
// This allows the user to paste text normally. Nedeed 'cause when you copy and paste
// text from Word, the clipboard data event is receiving an image because Word includes
// formatting information along with the text.
if (text && !isImageURL(text)) {
return;
}

event.preventDefault();
event.stopPropagation();
const { from } = getCursorPosition(view);

if (isImageURL(text)) {
if (isImageURL(text) && isNodeRegistered('image')) {
editor.chain().insertImage(text, from).addNextLine().run();
} else {
const file = files[0];
uploadAsset({ view, file, position: from });
}

event.preventDefault();
event.stopPropagation();
}

/**
Expand Down
Expand Up @@ -23,6 +23,14 @@ declare module '@tiptap/core' {
export const ImageNode = Image.extend({
name: 'dotImage',

addOptions() {
return {
inline: false,
allowBase64: true,
HTMLAttributes: {}
};
},

addAttributes() {
return {
src: {
Expand Down
2 changes: 1 addition & 1 deletion dotCMS/src/main/webapp/html/dotcms-block-editor.js

Large diffs are not rendered by default.

0 comments on commit 45d94c3

Please sign in to comment.