JiHong88 / suneditor

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

Incorrect isMobile detection in src/lib/util.js #1477

Open adamsarek opened 2 weeks ago

adamsarek commented 2 weeks ago

Describe the bug I found out a bug that when I press [ENTER], my editor loses focus to _focusTemp. I figured out it's caused by isMobile being true (defined in utils.js). Root of the problem is navigator.maxTouchPoints which is unreliable in Chrome due to some fluctuations. In my case it was equal to 10, even though I have no touch input and I'm on desktop. Based on this I think it should not be used as is in isMobile property check. I propose a slight change:

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

To Reproduce Steps to reproduce the behavior:

  1. Press [ENTER]
  2. Focus is on input (_focusTemp)

Expected behavior isMobile is false on desktop chrome.

Desktop

Release