GetmeUK / ContentTools

A JS library for building WYSIWYG editors for HTML content.
http://getcontenttools.com
MIT License
3.95k stars 395 forks source link

Desynchronization doesn't allowe to remove paragraph by backspace-key #457

Open theGrabix opened 6 years ago

theGrabix commented 6 years ago

It goes like that:

  1. start edition with contenttools on some empty page with just an empty paragraph
  2. input "xx"
  3. press "enter" [new paragraph appeared]
  4. press "backspace" [paragraph disappeared]
  5. press "enter" [again new paragraph appeared]
  6. input "y"
  7. press "backspace" [paragraph is empty again]
  8. press "backspace" [nothing happens; paragraph didn't disappear]

Interesting right? Once you enter text into paragraph, you cannot remove the paragraph (nor merge it with previous one) by pressing "backspace" at its beginning. I consider this a bug. I am using Firefox Quantium 57.0 (64 bits) on Windows 7.

I have made some debug using debugger in Firefox. Interestingly in function Text.prototype._keyBack statement "return" is executed in:

if (!(selection.get()[0] === 0 && selection.isCollapsed())) {
   return;
}

because selection.get()[0] return ONE instead of ZERO even though cursor is at the beginning of line. I think this is some effect of desynchronization between element.content and innerHTML. I don't remember now what i have exactly done, but i somehow got content.characters and it seem still have that last removed letter (here "y").

Anyway, even if i am wrong about how it works. I still think it is a bug. If I press "q" then "left" then "delete", then I am able to remove paragraph, but no if it WAS not empty and now IS empty. That is weird and am sure it shouldn't work like that.

anthonyjb commented 6 years ago

@theGrabix thanks for the report, I can confirm I'm able to reproduce this issue using the steps described - I may move the issue into ContentSelect as I think that's where the root of the problem is.