medium-editor icon indicating copy to clipboard operation
medium-editor copied to clipboard

First and last space of contenteditable nodes turn into  

Open sPaCeMoNk3yIam opened this issue 8 years ago • 7 comments

Description

If a contenteditable is split up into several nodes (e. g. by formatting) and one either deletes the last whitespace of a preceding or the first whitespace of a succeeding node and enters a whitespce again, this whitespace will be a non-breaking space.

Steps to reproduce

  1. Have several text nodes within a contenteditable
  2. Delete a leading or trailing whitespace
  3. Reenter a whitespace

Expected behavior: I expect no   when entering a simple whitespace. I only expect a non-breaking space when I specifically enter it (e. g. SHIFT + SPACE).

Actual behavior: Non-breaking spaces occur and are hard to tell for an author, without inspecting the website.

Link to an example: https://jsfiddle.net/spacemonk3y/406j52d7/ I built a simple example. Just delete the whitespce in front of the bold "foobar" and enter it again. I'll see a non-breaking space when inspecting with web developer tools. To see it happen also after "foobar", just add a second whitespace before "was" and delete it again. You'll see a   now...

Versions

  • medium-editor: none, since it's a contenteditable / browser problem
  • browser: Chrome 51
  • OS: Mac OS El Capitan 10.11.5

sPaCeMoNk3yIam avatar Aug 02 '16 15:08 sPaCeMoNk3yIam

@sPaCeMoNk3yIam so this appears to be a chrome-only issue as I wasn't able to get this to reproduce in firefox, safari, or IE11.

This is odd behavior indeed, if you keep adding spaces in it alternates between   and actual " " characters after each press of the spacebar.

To make these steps even more interesting, the location where the space is added is actually different from browser to browser. Chrome, Safari, and IE11 add the spaces within the <b> tag, Firefox adds the spaces to the text node after the <b> tag.

nmielnik avatar Aug 20 '16 13:08 nmielnik

This fix for this could just be as simple as look for &nbsp; elements within the whole editor, or within the currently edited element, and replace them with spaces.

nmielnik avatar Aug 20 '16 13:08 nmielnik

wouldn't say that this is a 'solution' as &nbsp;'s could be important to the author to keep...

sPaCeMoNk3yIam avatar Sep 06 '16 15:09 sPaCeMoNk3yIam

This is a Chrome bug. Seems like someone thinks its been solved even though I'm still seeing it on my up-to-date chrome.

https://bugs.chromium.org/p/chromium/issues/detail?id=310149

http://dev.ckeditor.com/ticket/11415 https://core.trac.wordpress.org/ticket/31157

jmgrill avatar Oct 25 '16 18:10 jmgrill

Yes, it is still happening. What the hay? I just want to format with tabs or spacebar. I do not want ANY actual whitespace.

Am I supposed to edit files only by downloading them and using my text editor and then uploading them again? It's not a problem - I am comfortable with FTP. But I need to know if I am just doing something wrong.

angela-smithers avatar Nov 27 '16 15:11 angela-smithers

Same issue here

ziedHamdi avatar May 14 '23 08:05 ziedHamdi

Same issue here

shabalinmax avatar Aug 14 '24 12:08 shabalinmax