JiHong88 / suneditor

Pure javascript based WYSIWYG html editor, with no dependencies.
http://suneditor.com
MIT License
1.67k stars 308 forks source link

Error pasting over the last word in Firefox #1342

Open pmympmm opened 7 months ago

pmympmm commented 7 months ago

Describe the bug On firefox if you have some text at the very end of the document, eg "one two three", and you select the last word then paste over it, the data pasted goes at the beginning of the sentence. If you have anything after, a full stop/period/other text/other lines it works as it should.

Seems to work fine on Chrome and only be a problem in firefox, I dont own a windows computer to check there.

To Reproduce Steps to reproduce the behavior:

  1. in Firefox Go to 'http://suneditor.com/sample/index.html'
  2. Copy some text from somewhere else, eg the word HELLO.
  3. Scroll down to end of the suneditor body and add a new line 'one two three' right at the bottom.
  4. double click the word 'three' so it is selected/highlighted
  5. paste over it
  6. HELLO goes the beginning of that line instead of the end.

Expected behavior 'one two HELLO' instead of 'HELLOone two'

Desktop (please complete the following information):

pmympmm commented 6 months ago

I'm not much of a js developer but I was trying to look through the code and see whats going on. I wonder if this bug is much more widespread and the cause of the others raised recently?

I suspect it's with the range (& selection), possible when the range has an endcontainer node instead of text.

in chrome if you make one letter in the middle of a word bold, eg "one two three" and select "tw" you can get a similar paste into the wrong position. same on firefox, though oddly if you select that text with keyboard(from right or left) or mouse from left it breaks, but it seems to work with mouse from right. In chrome it breaks all ways. In the one case it works range endOffset is 0, all other cases its 1.

I'll carry on having a look when I get a chance.