samclarke / SCEditor

A lightweight HTML and BBCode WYSIWYG editor
http://www.sceditor.com/
Other
660 stars 188 forks source link

Copy and paste into SCEditor removes some spaces #325

Closed q2apro closed 10 years ago

q2apro commented 10 years ago

My users recently discovered that copying and pasting text from Word or Open Office into the SCEditor will remove some arbitrary (?) white spaces.

To reproduce it:

  1. Copy the example text below and paste it into Microsoft Word (or Open Office)
  2. Open http://www.q2apro.com/forum/ask
  3. Copy the text from Word and paste it into the sceditor instance
  4. Click on "source" button
  5. Click again on the "source" button
  6. you will notice that the former space between darbas and dažnai is missing now

Example text:

Interviu: „Patirtis, žinios bei kruopštus rankų darbas dažnai daro stebuklus“.

Tested on: Win 7 (64 Bit), Word 2003, Firefox 31.0

How to solve this bug?

Is there a workaround, can I force paste as plain text somehow (I'm using the HTML plugin, not the bbcode)?

q2apro commented 10 years ago

See also screenrecording:

sceditor-bug-2

brunoais commented 10 years ago

I don't have MS word, I only have writer.

Get me a screenshot of the source HTML (using the browser's DOM inspector) right after you copy from MS word to SCE. Don't forget to fully extend the DOM tree. Then give me a copy of the contents that appear when you press to see the source code in SCE.

If Sam has MS word, then he might be able to assist on that.

q2apro commented 10 years ago

The source HTML in SCeditor right after the paste and hitting the source button:

<!-- [if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:WordDocument&gt;
  &lt;w:View&gt;Normal&lt;/w:View&gt;
  &lt;w:Zoom&gt;0&lt;/w:Zoom&gt;
  &lt;w:HyphenationZone&gt;21&lt;/w:HyphenationZone&gt;
  &lt;w:PunctuationKerning/&gt;
  &lt;w:ValidateAgainstSchemas/&gt;
  &lt;w:SaveIfXMLInvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;
  &lt;w:IgnoreMixedContent&gt;false&lt;/w:IgnoreMixedContent&gt;
  &lt;w:AlwaysShowPlaceholderText&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;
  &lt;w:Compatibility&gt;
   &lt;w:BreakWrappedTables/&gt;
   &lt;w:SnapToGridInCell/&gt;
   &lt;w:WrapTextWithPunct/&gt;
   &lt;w:UseAsianBreakRules/&gt;
   &lt;w:DontGrowAutofit/&gt;
  &lt;/w:Compatibility&gt;
  &lt;w:BrowserLevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;
 &lt;/w:WordDocument&gt;
&lt;/xml&gt;&lt;![endif] --> 
<p class="MsoNormal">
    Interviu: „Patirtis, žinios bei kruopštus rankų darbasdažnai daro stebuklus“.
</p>

<!-- [if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:LatentStyles DefLockedState=&quot;false&quot; LatentStyleCount=&quot;156&quot;&gt;
 &lt;/w:LatentStyles&gt;
&lt;/xml&gt;&lt;![endif] -->
<!-- [if gte mso 10]&gt;
&lt;style&gt;
 /* Style Definitions */
 table.MsoNormalTable
    {mso-style-name:&quot;Normale Tabelle&quot;;
    mso-tstyle-rowband-size:0;
    mso-tstyle-colband-size:0;
    mso-style-noshow:yes;
    mso-style-parent:&quot;&quot;;
    mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
    mso-para-margin:0cm;
    mso-para-margin-bottom:.0001pt;
    mso-pagination:widow-orphan;
    font-size:10.0pt;
    font-family:&quot;Times New Roman&quot;;
    mso-ansi-language:#0400;
    mso-fareast-language:#0400;
    mso-bidi-language:#0400;}
&lt;/style&gt;
&lt;![endif] -->
brunoais commented 10 years ago

Also show me the source HTML before hitting the source button please.

q2apro commented 10 years ago

Before hitting the source button:

<body dir="ltr" contenteditable="true"><!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:View>Normal</w:View>
  <w:Zoom>0</w:Zoom>
  <w:HyphenationZone>21</w:HyphenationZone>
  <w:PunctuationKerning/>
  <w:ValidateAgainstSchemas/>
  <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
  <w:IgnoreMixedContent>false</w:IgnoreMixedContent>
  <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
  <w:Compatibility>
   <w:BreakWrappedTables/>
   <w:SnapToGridInCell/>
   <w:WrapTextWithPunct/>
   <w:UseAsianBreakRules/>
   <w:DontGrowAutofit/>
  </w:Compatibility>
  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
 </w:WordDocument>
</xml><![endif]-->

<p class="MsoNormal">Interviu: „Patirtis, žinios bei kruopštus rankų darbas
dažnai daro stebuklus“.</p>

<!--[if gte mso 9]><xml>
 <w:LatentStyles DefLockedState="false" LatentStyleCount="156">
 </w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
 /* Style Definitions */
 table.MsoNormalTable
    {mso-style-name:"Normale Tabelle";
    mso-tstyle-rowband-size:0;
    mso-tstyle-colband-size:0;
    mso-style-noshow:yes;
    mso-style-parent:"";
    mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
    mso-para-margin:0cm;
    mso-para-margin-bottom:.0001pt;
    mso-pagination:widow-orphan;
    font-size:10.0pt;
    font-family:"Times New Roman";
    mso-ansi-language:#0400;
    mso-fareast-language:#0400;
    mso-bidi-language:#0400;}
</style>
<![endif]--></body>

As I see now there is a line break instead a space after the word darbas.

brunoais commented 10 years ago

Sounds like that, yes. but... Where does that line come from? Try with other browsers... Try chrome, for example. Do you have the same result? How about if you explicitly place a new line on that spot in the word document? Does it create a <br> when you paste to SCE? How about with different texts? Try changing the sizes of the words. Does this repeat? Does that new line have any relation with the line wrapping of MS Word? If you do, then the one with the bug is probably MS word and not SCE.

q2apro commented 10 years ago

Before I dive into it more, is there a plain-text option of SCE? I have only seen that option with the bbcode plugin.

If not, maybe we could use some jquery like stated here: http://jsfiddle.net/erikwoods/Ee3yC/ or like here: http://stackoverflow.com/a/17545260/1066234

PS: Side note: If enablePasteFiltering: true then the replacement of the spaces takes place immediately.

brunoais commented 10 years ago

You mean... Plain text paste? You may make one, if you want, as a command. It should be straight forward. You may also paste the contents in the source code mode.

q2apro commented 10 years ago

Looks like one year ago someone had a similar issue with Word 2010 and Firefox + Chrome: https://github.com/samclarke/SCEditor/issues/88 (closed as solved) - but the bug still exists.

PS: We really need a paste-as-plain-text option.

brunoais commented 10 years ago

Which version of SCE are you using? (just checked... Some build of 1.4.5)

Try using the latest version and see if that still remains.

q2apro commented 10 years ago

I am using 1.4.5.

I have also tried with latest 1.4.6-dev - still the same problem.

samclarke commented 10 years ago

Thanks for reporting! Fixed in the 1.4.6-dev branch which I'm hoping to release fairly soon.

q2apro commented 10 years ago

Fix confirmed.

PS: How I love these fixes that require only one char to be added, esp. if it is a white space! ;-)