Opened 13 years ago

Closed 13 years ago

Last modified 10 years ago

#6751 closed Bug (fixed)

Paste from Word - Leading space disappears (in formatted block)

Reported by: Frédéric Arène Owned by: Garry Yao
Priority: Normal Milestone: CKEditor 3.5.3
Component: Plugin : Paste from Word Version: 3.2
Keywords: Cc: farene@…

Description

When I paste from Word formatted text like this one :

<span>A b<b> c d</b></span>

it outputs this in CKEditor :

<p>
	A b<b>c d</b></p>

...with the formatting rendered, it's like that : A b c d -> A bc d

The space betwwen 'b' and 'c' disappeared, (probably somewhere in the htmlWriter).

Attachments (4)

TextToPaste.doc (19.5 KB) - added by Frédéric Arène 13 years ago.
Very simple MSWord document to reproduce the bug.
disappearing_spaces_example2.docx (10.5 KB) - added by Tomas 13 years ago.
Yet another example of more disappearing spaces.
6751.docx (12.5 KB) - added by Wiktor Walc 13 years ago.
6751.patch (2.8 KB) - added by Garry Yao 13 years ago.

Download all attachments as: .zip

Change History (18)

Changed 13 years ago by Frédéric Arène

Attachment: TextToPaste.doc added

Very simple MSWord document to reproduce the bug.

comment:1 Changed 13 years ago by Frédéric Arène

Cc: farene@… added

comment:2 Changed 13 years ago by Krzysztof Studnik

Status: newconfirmed

Confirmed for 3.4.3 & 3.5

comment:3 Changed 13 years ago by Krzysztof Studnik

Keywords: MSWord space formatted removed
Version: 3.4.3 (SVN - trunk)3.2

Does not occur in CKEditor 3.1.1,

Changed 13 years ago by Tomas

Yet another example of more disappearing spaces.

comment:4 Changed 13 years ago by Tomas

Comment added another example of more spaces that disappears when pasting from word. In the example all spaces after words between styling disappear.

trailing space also disappears if first word in document is styled, but the trailing space is not. i.e. <p><b>A<b> B</p> -> <p><b>A<b>B</p> (that is not in the example document.)

Changed 13 years ago by Wiktor Walc

Attachment: 6751.docx added

comment:5 Changed 13 years ago by Wiktor Walc

Check the attached file for one more example (I have used different fonts to reproduce it).

comment:6 Changed 13 years ago by Tomas

The problem here is occuring in the function parser.onText() in core\htmlparser\fragment.js

The problem occurs when a span element has been parsed, the code in on text will then call trimLeft, this will cause the space to disappear. This is the code that trims it away (from fragment.js)

if ( !currentNode._.hasInlineStarted && !inPre )
			{
				text = CKEDITOR.tools.ltrimSpecial( text );
				//text = CKEDITOR.tools.ltrim( text );

				if ( text.length === 0 )
					return;
			}

I tried to understand and fix this, but I really dont understand why it is trimmed, I made a local tweak in my installation for this, but it would be great if one of the core developers could have a look at this.

I ended up trimming, if and only if there are more than one space. Ugly fix, but it solves my problem.

comment:7 in reply to:  6 Changed 13 years ago by Tomas

the commented out code is the original code, ltrimSpecial looks like this, if anyone is intrested.

 ltrimSpecial : (function()
		{
			//do not delete a single space, as it probably should be there.
			var trimRegex = /^[ ]{2,}|^[\t\n\r]+/g;
			return function( str )
			{
				return str.replace( trimRegex, '' ) ;
			};
		})(),

comment:8 Changed 13 years ago by Wiktor Walc

Keywords: HasPatch added
Milestone: CKEditor 3.5.3

Changed 13 years ago by Garry Yao

Attachment: 6751.patch added

comment:9 Changed 13 years ago by Garry Yao

Keywords: HasPatch removed
Owner: set to Garry Yao
Status: confirmedreview

@toma25 It's not the parser::onText that is not doing anything wrong as whitespace works well when loading from source.

Proposing context-sensitive parsing as the filter might choose to re-parse the inner html of potentially any element.

comment:10 in reply to:  9 Changed 13 years ago by Tomas

Replying to garry.yao:

@toma25 It's not the parser::onText that is not doing anything wrong as whitespace works well when loading from source.

Proposing context-sensitive parsing as the filter might choose to re-parse the inner html of potentially any element.

Will not argue against you, as I wrote, the code supplied is probably not the right fix, but it did solve my problem. Again, I suggest that one of the developers that understand the code takes a look at this.

comment:11 Changed 13 years ago by Garry Yao

@toma25 Thanks for the input, we've taken your patch into consideration, pls trust the team and wait for the ticket to be fixed.

comment:12 Changed 13 years ago by Sa'ar Zac Elias

Status: reviewreview_passed

comment:13 Changed 13 years ago by Garry Yao

Resolution: fixed
Status: review_passedclosed

Fixed with [6557].

comment:14 Changed 10 years ago by Frederico Caldeira Knabben

Component: Core : PastingPlugin : Paste from Word
Note: See TracTickets for help on using tickets.
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy