Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#9354 closed Bug (invalid)

[ Firefox] Copy/Paste not working as intended in Firefox15.0.1

Reported by: S Owned by:
Priority: Normal Milestone:
Component: Core : Pasting Version: 3.4.1
Keywords: Cc:

Description

I am trying to copy and paste some text from a word document (containing bullets). Only the text above the bullets is copied, rest of the content is excluded for some reason. This happens in firefox 15.0.1, but works fine in internet explorer and chrome. In our ckeditor config, "forcePasteAsPlainText" is set to "TRUE". I am attaching the text we are trying to copy/paste and also a screenshot of the result. Please take a look into the issue. Thanks.

Attachments (1)

ckeditor_issue.docx (19.1 KB) - added by S 7 years ago.

Download all attachments as: .zip

Change History (9)

Changed 7 years ago by S

Attachment: ckeditor_issue.docx added

comment:1 Changed 7 years ago by S

Summary: Copy/Paste not working as intended in Firefox15.0.1[ Firefox] Copy/Paste not working as intended in Firefox15.0.1

comment:2 Changed 7 years ago by Timo

I am experiencing the same issue and I suspect that Firefox has enabled some sort of security setting that disallows multiple execCommands. In more recent versions this problem does not occur.

Last edited 7 years ago by Timo (previous) (diff)

comment:3 Changed 7 years ago by S

Thank you, for your response. I was trying to find a solution for this issue and I came with a temporary solution using the "on" event trigger of the ckeditor. I am replacing the text in the editor using the "paste" event which happens only if it is firefox 15.0.1. I didn't have to make any changes to the ckeditor's javascript. I don't know if it is an elegant solution, but took care of the issue for now. I will give your solution a try. Please let me know if there are any issues with the fix I am cuurently using.

instance.on("paste", function(e) {e.editor.setData(e.data.text.replace(/\n/g,'<br>'));});

comment:4 Changed 7 years ago by Timo

The best thing is to update your editor to the latest version, where this issue is no longer around. In my situation it was an older version of our CMS, do I rewrote the method insertText in plugins/pastetext/plugin.js to use the exeCommand() only once:

CKEDITOR.editor.prototype.insertText = function( text )
{
    this.focus();
    this.fire( 'saveSnapshot' );

    var mode = this.getSelection().getStartElement().hasAscendant( 'pre', true ) ? CKEDITOR.ENTER_BR : this.config.enterMode,
        isEnterBrMode = mode == CKEDITOR.ENTER_BR,
        doc = this.document.$,
        self = this,
        line;

    text = CKEDITOR.tools.htmlEncode( text.replace( /\r\n|\r/g, '\n' ) );

    var formatted   = text.match(/\n+/g) ? '' : text;
    var startIndex  = 0;
    text.replace( /\n+/g, function( match, lastIndex )
    {
        line = text.substring( startIndex, lastIndex );
        startIndex = lastIndex + match.length;
        if (!line.length)
            return;

        if (formatted.length) {
            var lineBreakNums = match.length,
                // Duo consequence line-break as a enter block.
                enterBlockTimes = isEnterBrMode ? 0 : Math.floor( lineBreakNums / 2 ),
                // Per link-break as a enter br.
                enterBrTimes = isEnterBrMode ? lineBreakNums : lineBreakNums % 2;

            for(var i = 0; i < enterBlockTimes; i++)
                formatted = formatted + '</p><p>';
            for(i = 0; i < enterBrTimes; i++)
                formatted = formatted + '<br />';
        }
        formatted = formatted + line;
    });

    doInsertText(doc, formatted);
    this.fire( 'saveSnapshot' );
};

comment:5 Changed 7 years ago by Jakub Ś

Keywords: copy paste firefox 15.0.1 bullets removed
Resolution: invalid
Status: newclosed

This issue no longer occurs in latest CKEDitor 3.6.4. Please upgrade as early as possible.
I'm closing this issue as invalid because it concerns bug which was fixed in current version.

---

NOTE:

In our ckeditor config, "forcePasteAsPlainText" is set to "TRUE".

As written in docs forcePasteAsPlainText has no influence on paste from Word option http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html#.forcePasteAsPlainText

I'm not sure if you want to keep styles of contents pasted from word or have everything in plain text form.
If you want to keep styles please use below in config.js:

config.pasteFromWordRemoveFontStyles=false;
config.pasteFromWordRemoveStyles=false;

If you want to keep plain text, then you don't have to set anything as these options are set to true by default.

comment:6 in reply to:  4 Changed 7 years ago by S

Thanks for taking time to help me, we are upgrading to latest version of ckeditor.

Replying to timo:

The best thing is to update your editor to the latest version, where this issue is no longer around. In my situation it was an older version of our CMS, do I rewrote the method insertText in plugins/pastetext/plugin.js to use the exeCommand() only once:

CKEDITOR.editor.prototype.insertText = function( text )
{
    this.focus();
    this.fire( 'saveSnapshot' );

    var mode = this.getSelection().getStartElement().hasAscendant( 'pre', true ) ? CKEDITOR.ENTER_BR : this.config.enterMode,
        isEnterBrMode = mode == CKEDITOR.ENTER_BR,
        doc = this.document.$,
        self = this,
        line;

    text = CKEDITOR.tools.htmlEncode( text.replace( /\r\n|\r/g, '\n' ) );

    var formatted   = text.match(/\n+/g) ? '' : text;
    var startIndex  = 0;
    text.replace( /\n+/g, function( match, lastIndex )
    {
        line = text.substring( startIndex, lastIndex );
        startIndex = lastIndex + match.length;
        if (!line.length)
            return;

        if (formatted.length) {
            var lineBreakNums = match.length,
                // Duo consequence line-break as a enter block.
                enterBlockTimes = isEnterBrMode ? 0 : Math.floor( lineBreakNums / 2 ),
                // Per link-break as a enter br.
                enterBrTimes = isEnterBrMode ? lineBreakNums : lineBreakNums % 2;

            for(var i = 0; i < enterBlockTimes; i++)
                formatted = formatted + '</p><p>';
            for(i = 0; i < enterBrTimes; i++)
                formatted = formatted + '<br />';
        }
        formatted = formatted + line;
    });

    doInsertText(doc, formatted);
    this.fire( 'saveSnapshot' );
};

comment:7 in reply to:  5 Changed 7 years ago by S

We are upgrading to ckeditor 3.6.4. Thanks for the help. Word has some formatting which is specific to their software, when our users copy/paste content from word, these characters are being brought into our system so we are using "forcePasteAsPlainText" to remove all the word specific fomatting.

Replying to j.swiderski:

This issue no longer occurs in latest CKEDitor 3.6.4. Please upgrade as early as possible.
I'm closing this issue as invalid because it concerns bug which was fixed in current version.

---

NOTE:

In our ckeditor config, "forcePasteAsPlainText" is set to "TRUE".

As written in docs forcePasteAsPlainText has no influence on paste from Word option http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html#.forcePasteAsPlainText

I'm not sure if you want to keep styles of contents pasted from word or have everything in plain text form.
If you want to keep styles please use below in config.js:

config.pasteFromWordRemoveFontStyles=false;
config.pasteFromWordRemoveStyles=false;

If you want to keep plain text, then you don't have to set anything as these options are set to true by default.

comment:8 Changed 7 years ago by Jakub Ś

If it works for you then fine but please understand one thing:
Option forcePasteAsPlainText has no influence on pastefromword plugin. Please see http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html#.forcePasteAsPlainText
To paste only as plain text besides setting forcePasteAsPlainText you would have to also remove pastefromword plugin.

There two are options (below are default settings) which remove certain word styles

config.pasteFromWordRemoveFontStyles=true;
config.pasteFromWordRemoveStyles=true;

For any other non-standard cleanups you would have to use http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html#.pasteFromWordCleanupFile where you specify file wilh cleaning rules.
Normally users take file \ckeditor\_source\plugins\pastefromword\filter\default.js, paste some rules (usually at the end of cleanWord function) and build new release (Some users simply take this modified source file and paste it in release folder - \ckeditor\plugins\pastefromword\filter\default.js).

Note: See TracTickets for help on using tickets.
© 2003 – 2019 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy