Page MenuHomePhabricator

CodeMirror: Disable line numbers for mobile devices
Closed, ResolvedPublic3 Estimated Story Points

Description

There's an issue when using line numbers and editing on mobile devices, see T285204: Can't remove lines with syntax highlight on Android. It's upstream in the CodeMirror library and will probably only be fixed with the new major release 6.x. Until then we should disable the feature for these devices, to avoid any inconveniences for affected editors.

Acceptance criteria:

  • Line numbers are disabled for mobile devices on all namespaces ( independent of skin & desktop/mobile mode )

Notes:

  • CodeMirror includes a detection for mobile devices that could be used, if using the detection in core is not convenient

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript
thiemowmde moved this task from Sprint Backlog to Doing on the WMDE-TechWish-Sprint-2021-09-01 board.
thiemowmde subscribed.

I had a look at some code we might want to use:

  • Since 2016, core does feature detection instead of user-agent sniffing, see resources/src/startup/startup.js. This means it mostly doesn't care about the exact browser, but about it's capabilities.
  • The only bit of information we get from there is <html class="client-js"> vs. <html class="client-nojs">. This is of no use for us. CodeMirror won't even be activated in the later case.
  • Another bit of feature detection is in resources/src/startup/mediawiki.loader.js. This can be used by setting "requiresES6": true on a MediaWiki-ResourceLoader module in extension.json. Hard to tell if this will help us. Having the capability to run ES6 code is not really related to the bug we are dealing with, I believe.
  • MobileFrontend does have a $wgMFAutodetectMobileView setting. This enables something called a DeviceDetectorService which tries to detect "mobile" as well as "tablet" devices based on a wide variety of signals. The code for this was introduced in 2016 via https://gerrit.wikimedia.org/r/313381 (T143891). I believe it's of no use for us. Mostly because it doesn't return anything specific, only two boolean flags.
  • CodeMirror 5 does rather trivial user-agent sniffing. Unfortunately there is no way to access this information.
  • CodeMirror 6 continues to do pretty much the same (a little more specific, now containing a \b delimiter and not being case-insensitive any more).

The best solution I can see so far is to copy what CodeMirror 6 does.

What I would love to know is if the relevant bug was fixed, and in which version of the Android browser. CodeMirror mentions version 56. The original ticket T285204 was about versions 90 and 91. The most recent version according to https://chromereleases.googleblog.com is 95. Which means it was most probably never fixed.

Change 717160 had a related patch set uploaded (by Thiemo Kreuz (WMDE); author: Thiemo Kreuz (WMDE)):

[mediawiki/extensions/CodeMirror@master] Disable line numbering in all Android browser versions

https://gerrit.wikimedia.org/r/717160

What I would love to know is if the relevant bug was fixed, and in which version of the Android browser. CodeMirror mentions version 56. The original ticket T285204 was about versions 90 and 91. The most recent version according to https://chromereleases.googleblog.com is 95. Which means it was most probably never fixed.

I just verified the bug on my Android 10 with FF 91.

I also tested iOS 14 with Safari/Chrome/FF and it's not an issue there. So it could be sufficient to disable it for Android devices only. Might be good to have a Windows phone checked as well, but I'm not sure if that's available.

I tried SauceLabs to cover a few more combinations. The emulation in there gives different results than my phone so I guess it cant be trusted completely.

Change 717160 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] Disable line numbering in all Android browser versions

https://gerrit.wikimedia.org/r/717160

thiemowmde moved this task from Demo to Done on the WMDE-TechWish-Sprint-2021-09-01 board.

Confirmed on two different devices (two I never tested this with before). A phone running Android 11 and a tablet running Android 9.

20210914_111717_resized_.jpg (576×1 px, 76 KB)