JiHong88 / suneditor

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

After pressing the enter key, focus jumps to the top of the page. #1407

Open malworthy opened 1 month ago

malworthy commented 1 month ago

Details After pressing the enter key, focus jumps to the top of the page.

To Reproduce Can be replicated in the options sample: http://suneditor.com/sample/html/options.html Click into the editor. Press enter key. Focus will go to the top of the screen.

Only happens in v2.46.3 of Suneditor, Issue not present in v2.45.1

Expected behaviour For focus to stay in the control after pressing the enter key

andylwelch commented 3 weeks ago

I am also experiencing the issue with lost focus on enter key presses. It started occuring in v2.46.0. Looking through the change logs I suspect this change set

Specifically e.preventDefault() is changed to call event._enterPrevent(e)

image

and there is an _enterPrevent() which triggers a focus event elsewhere: this.__focusTemp.focus();

image

Thanks for your efforts!

alexlaw-leo commented 2 days ago

I think you're on to something there.

We've had a few people with laptops experience this, but most with laptops or desktops have no issue. Until I read this thread yesterday I couldn't reproduce it on my desktop.

This morning I learned how to set the user agent in Chrome, I chose iPad to make it appear mobile, and this trips the issue consistently. I've tested both in our application and at http://suneditor.com/sample/index.html

I'm not convinced it's the user agent necessarily, though. Perhaps something else in this:

this.isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0;

EDIT: OK, now I'm sure it's the touch points test. It's being flagged as a mobile device on our laptops that support touch screen input.

image

alexlaw-leo commented 2 days ago

OK, I've messed about with this to trip or prevent the issue:

image

I have no solution at this point other than locking the version of the library at 2.45.1.

malworthy commented 2 days ago

The laptop I'm experiencing this issue on has a touchscreen - so touch points theory hold up.

BestLemoon commented 2 hours ago

same problem, but solved by locking to v2.45.1