Ticket #6751 (closed Bug: fixed)

Opened 3 years ago

Last modified 3 months ago

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

Reported by: gillup 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

TextToPaste.doc (19.5 KB) - added by gillup 3 years ago.
Very simple MSWord document to reproduce the bug.
disappearing_spaces_example2.docx (10.5 KB) - added by toma25 3 years ago.
Yet another example of more disappearing spaces.
6751.docx (12.5 KB) - added by wwalc 3 years ago.
6751.patch (2.8 KB) - added by garry.yao 3 years ago.

Change History

Changed 3 years ago by gillup

Very simple MSWord document to reproduce the bug.

comment:1 Changed 3 years ago by gillup

  • Cc farene@… added

comment:2 Changed 3 years ago by krst

  • Status changed from new to confirmed

Confirmed for 3.4.3 & 3.5

comment:3 Changed 3 years ago by krst

  • Keywords MSWord space formatted removed
  • Version changed from 3.4.3 (SVN - trunk) to 3.2

Does not occur in CKEditor 3.1.1,

Changed 3 years ago by toma25

Yet another example of more disappearing spaces.

comment:4 Changed 3 years ago by toma25

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 3 years ago by wwalc

comment:5 Changed 3 years ago by wwalc

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

comment:6 follow-up: ↓ 7 Changed 3 years ago by toma25

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 3 years ago by toma25

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 3 years ago by wwalc

  • Keywords HasPatch added
  • Milestone set to CKEditor 3.5.3

Changed 3 years ago by garry.yao

comment:9 follow-up: ↓ 10 Changed 3 years ago by garry.yao

  • Keywords HasPatch removed
  • Owner set to garry.yao
  • Status changed from confirmed to review

@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 3 years ago by toma25

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 3 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 3 years ago by Saare

  • Status changed from review to review_passed

comment:13 Changed 3 years ago by garry.yao

  • Status changed from review_passed to closed
  • Resolution set to fixed

Fixed with [6557].

comment:14 Changed 3 months ago by fredck

  • Component changed from Core : Pasting to Plugin : Paste from Word
Note: See TracTickets for help on using tickets.
© 2003 – 2012 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy