react-draft-wysiwyg icon indicating copy to clipboard operation
react-draft-wysiwyg copied to clipboard

copy/paste problems

Open GreatItLove opened this issue 8 years ago • 12 comments

it is not working properly on copy/paste event. for example, it cant copy bold style text and another thing is that when you paste something, the line height is too high and each line, there is additional paragraph.

Let me know how to solve these issues.

Thanks.

GreatItLove avatar Oct 12 '17 16:10 GreatItLove

this component do pasting better : https://github.com/froala/react-froala-wysiwyg

sneerin avatar Nov 13 '17 23:11 sneerin

try to add handlePastedText <Editor handlePastedText={() => false} />

o-svetlichnyi avatar Oct 20 '18 23:10 o-svetlichnyi

try to add handlePastedText <Editor handlePastedText={() => false} />

This worked well for me, unfortunately, it's nowhere to be found in the documentation.

aaronjhoffman avatar Nov 08 '18 07:11 aaronjhoffman

handlePastedText={() => false}

@aaronjhoffman Can you please file an issue on it? since you know much about it. Please.

aberba avatar Nov 08 '18 09:11 aberba

handlePastedText={() => false} it workes on Linux but does not work on mac 😕

nelsoneldoro avatar Feb 07 '19 17:02 nelsoneldoro

Based on https://github.com/jpuri/react-draft-wysiwyg/blob/7b328659f1251a17a2547b357b41502dcc25611b/src/utils/handlePaste.js I have swiped the lib that converts html to draft. I have used draft-js-import-html

import {Editor} from 'react-draft-wysiwyg';
import {stateFromHTML} from 'draft-js-import-html';

...

handlePastedText = (text, html, editorState, onChange) => {
    const selectedBlock = getSelectedBlock(editorState);
    if (selectedBlock && selectedBlock.type === 'code') {
      const contentState = Modifier.replaceText(
        editorState.getCurrentContent(),
        editorState.getSelection(),
        text,
        editorState.getCurrentInlineStyle(),
      );
      onChange(EditorState.push(editorState, contentState, 'insert-characters'));
      return true;
    } else if (html) {
      const blockMap = stateFromHTML(html).blockMap;
      const newState = Modifier.replaceWithFragment(
        editorState.getCurrentContent(),
        editorState.getSelection(),
        blockMap,
      );
      onChange(EditorState.push(editorState, newState, 'insert-fragment'));
      return true;
    }
    return false;
};

nelsoneldoro avatar Feb 08 '19 12:02 nelsoneldoro

Based on https://github.com/jpuri/react-draft-wysiwyg/blob/7b328659f1251a17a2547b357b41502dcc25611b/src/utils/handlePaste.js I have swiped the lib that converts html to draft. I have used draft-js-import-html

import {Editor} from 'react-draft-wysiwyg';
import {stateFromHTML} from 'draft-js-import-html';

...

handlePastedText = (text, html, editorState, onChange) => {
    const selectedBlock = getSelectedBlock(editorState);
    if (selectedBlock && selectedBlock.type === 'code') {
      const contentState = Modifier.replaceText(
        editorState.getCurrentContent(),
        editorState.getSelection(),
        text,
        editorState.getCurrentInlineStyle(),
      );
      onChange(EditorState.push(editorState, contentState, 'insert-characters'));
      return true;
    } else if (html) {
      const blockMap = stateFromHTML(html).blockMap;
      const newState = Modifier.replaceWithFragment(
        editorState.getCurrentContent(),
        editorState.getSelection(),
        blockMap,
      );
      onChange(EditorState.push(editorState, newState, 'insert-fragment'));
      return true;
    }
    return false;
};

thx for the code, but it won't work with the pasted word has backgroundColor , any suggestion for me ? QAQ

Fredxingxing avatar Jun 27 '19 14:06 Fredxingxing

try to add handlePastedText <Editor handlePastedText={() => false} />

This solution worked for me too, thx. Should be in the documentation! But it doesn't work with the pasted word has backgroundColor

latati avatar Jan 28 '21 18:01 latati

try to add handlePastedText <Editor handlePastedText={() => false} />

Good job :))

dattruong88vn avatar May 10 '21 10:05 dattruong88vn

cố gắng thêm handlePastedText <Editor handlePastedText={() => false} />

amazing good job iem 👍︎

chuoidamduoi avatar Apr 14 '22 03:04 chuoidamduoi

<Editor handlePastedText={() => false} /> work perfectly :)

paulomatos777 avatar Nov 10 '22 14:11 paulomatos777

you can also do stripPastedStyles={true}

https://github.com/jpuri/react-draft-wysiwyg/issues/552#issuecomment-398294694

fudgi avatar Apr 08 '24 11:04 fudgi