Directory

⚓ T365311 Syntax highlighter is broken on Dark Mode
Page MenuHomePhabricator

Syntax highlighter is broken on Dark Mode
Closed, ResolvedPublicBUG REPORT

Assigned To
Authored By
Theklan
May 18 2024, 8:37 AM
Referenced Files
F57461667: 2024-09-04_15-35-30.mp4.gif
Sep 4 2024, 11:17 PM
F57461664: 2024-09-04_15-34-55.mp4.gif
Sep 4 2024, 11:17 PM
F57461662: 2024-09-04_15-32-50.mp4.gif
Sep 4 2024, 11:17 PM
F57461658: 2024-09-04_15-31-59.mp4.gif
Sep 4 2024, 11:17 PM
F57437811: 2024-09-03_14-13-56.png
Sep 3 2024, 10:11 PM
F57437744: 2024-09-03_14-09-56.mp4.gif
Sep 3 2024, 10:11 PM
F56733530: image.png
Jul 27 2024, 9:30 PM
F56343386: en.wikipedia.org_wiki_Special_Preferences(iPad Air).png
Jul 11 2024, 12:50 AM
Tokens
"The World Burns" token, awarded by Sjoerddebruin."Blobhaj" token, awarded by taavi."Y So Serious" token, awarded by Ash_Crow.

Description

Steps to replicate the issue (include links if applicable):

  • Visit Special:Preferences and enable syntax highlighting
  • Choose Dark Mode
  • Click on "Edit source"
  • Activate "Syntax highlighting"

What happens?:
Normal:

irudia.png (394×1 px, 54 KB)

Activated:

irudia.png (433×1 px, 59 KB)

What should have happened instead?: Colors should change also with Dark Mode.

Software version (on Special:Version page; skip for WMF-hosted wikis like Wikipedia):

Other information (browser name/version, screenshots, etc.):

Patch Demo

To test the 2017 editor, login as Alice with password patchdemo1.

Requirement

Ensure that syntax highlighting in dark mode is functional and legible for the wikitext editor.

BDD

Feature: Functional Syntax Highlighting in Dark Mode

  Scenario: Syntax highlighting works correctly in dark mode
    Given the user has enabled syntax highlighting
    And the user has enabled dark mode
    When the user opens the wikitext editor
    Then the syntax highlighting should be functional
    And the colors should change to be compatible with dark mode
    And all text should be legible

Test Steps

Test Case 1: Verify Syntax Highlighting in Dark Mode

  1. Visit Special:Preferences and enable syntax highlighting
  2. Enable dark mode.
  3. Navigate to this edit page.
  4. Activate "Syntax highlighting".
  5. AC1: Confirm that the syntax highlighting is functional. Confirm that the colors are compatible with dark mode. Confirm that all text is legible.

QA Results - Patch Demo

ACStatusDetails
1T365311#10119852

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes

See resources/mode/mediawiki/colorblind-colors.less for related styles.

So, the edit page is now enabled for dark mode. I'm unable to do edits without syntax highlighting and I can't keep switching modes all the time...

@MusikAnimal could we add skin-theme and noinvert along with cm-mw-colorblind-colors in the mean time?

@Sjoerddebruin perhaps try this in your user CSS as a workaround - does that help?:

.cm-mw-colorblind-colors { filter: invert(1); }

@MusikAnimal could we add skin-theme and noinvert along with cm-mw-colorblind-colors in the mean time?

@Sjoerddebruin perhaps try this in your user CSS as a workaround - does that help?:

.cm-mw-colorblind-colors { filter: invert(1); }

At the moment I'm using this user script:

const observer = new MutationObserver((mutationsList) => {
	mutationsList.forEach(mutation => {
		mutation.addedNodes.forEach(node => {
			if (node.classList && node.classList.contains('CodeMirror')) {
				node.classList.add('notheme', 'skin-invert');
			}
		});
	});
});

observer.observe(document.body, {
	childList: true,
	subtree: true
});

Which is workable for the time being.

Okay that suggests notheme and skin-invert can be added effectively here which is good news!

image.png (612×1 px, 156 KB)

It's readable for me but not sure if it checks all the contrast stuff, also some colours looks a bit too same to each other.

@Jdlrobson, I can't seem to get any syntax highlighting to show up in prod. Any ideas?

en.wikipedia.org_wiki_Special_Preferences(iPad Air).png (4×1 px, 778 KB)

@MusikAnimal could we add skin-theme and noinvert along with cm-mw-colorblind-colors in the mean time?

https://www.mediawiki.org/wiki/Help:Extension:CodeMirror#Color_and_style_customization has examples of the palette (see also colorblind mode). Someone who understands the accessibility requirements should be able to come up with a suitable palette easily enough, I would think. But at any rate, I'm afraid I'm terribly busy with the #community_wishlist_survey which coincidentally has the same launch date as dark mode… :( So I won't be around to help much, sorry! Adding the skin-theme/noinvert solution as a short-term solution is fine as well. I will have more time to help with this after July 15.

With dark mode being more rolled out now could we please add the CSS classes for the time being?

Change #1057364 had a related patch set uploaded (by Sjoerddebruin; author: Sjoerddebruin):

[mediawiki/extensions/CodeMirror@master] Apply color inversion until dark syntax styles are chosen

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

Classes are inserted on the correct element with the above patch:

image.png (46×838 px, 33 KB)

Change #1057364 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] Apply color inversion until dark syntax styles are chosen

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

This is now live on www.mediawiki.org - is it working as expected @Sjoerddebruin ?

This is now live on www.mediawiki.org - is it working as expected @Sjoerddebruin ?

CM6 is enabled on mediawiki.org, so you'll need to test on a different wiki, since the patches only touched CM5.

I'll look into a proper fix for both CM5 and CM6 styles today.

Change #1059166 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[mediawiki/extensions/CodeMirror@master] [WIP] Implement dark mode styles

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

Change #1059170 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[mediawiki/skins/Vector@master] clientPreferenes: fire hook when client preferences change

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

The temporary color inversion doesn't work with os clientpref by the way.

The temporary color inversion doesn't work with os clientpref by the way.

Interesting, doesn't sound like expected behaviour to me...

Change #1059170 abandoned by MusikAnimal:

[mediawiki/skins/Vector@master] clientPreferenes: fire hook when client preferences change

Reason:

no longer needed! See I6a3bbc6bce4

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

MusikAnimal updated Other Assignee, added: Sjoerddebruin; removed: MusikAnimal.

Proper dark mode styles are now ready for review: https://gerrit.wikimedia.org/r/c/mediawiki/extensions/CodeMirror/+/1059166

This includes reworking the search panel to use Codex CSS components (T371436), which in turn gives us dark mode styles for free.

Proper dark mode styles are now ready for review: https://gerrit.wikimedia.org/r/c/mediawiki/extensions/CodeMirror/+/1059166

This includes reworking the search panel to use Codex CSS components (T371436), which in turn gives us dark mode styles for free.

Can we test this on a Patch Demo? Not sure which settings are required for Vector dark mode...

The temporary color inversion doesn't work with os clientpref by the way.

Which wiki were you testing this on? And are you referring to the latest patch from @MusikAnimal or what's in production right now? Can you please share some replication steps? Thanks in advance! I've checked skin-invert class - and it is working as expected in the automatic mode.

Sure. I was referring to the current approach using skin-invert in codemirror and the 2010 wikitext editor.

  1. open https://de.wikipedia.org/w/index.php?title=Schneidengruppe&action=edit&useskin=vector-2022&safemode=1 with accessibility for reading beta function activated
  2. enable automatic color mode in accessibility menu
  3. toggle dark mode in browser
    • --> non-highlighted text keeps being black on dark background and is unreadable
  4. enable dark color mode in accessibility menu
    • --> non-highlighted text turns white on dark background and is readable

Sure. I was referring to the current approach using skin-invert in codemirror and the 2010 wikitext editor.

  1. open https://de.wikipedia.org/w/index.php?title=Schneidengruppe&action=edit&useskin=vector-2022&safemode=1 with accessibility for reading beta function activated
  2. enable automatic color mode in accessibility menu
  3. toggle dark mode in browser
    • --> non-highlighted text keeps being black on dark background and is unreadable
  4. enable dark color mode in accessibility menu
    • --> non-highlighted text turns white on dark background and is readable

I can confirm this bug is fixed with https://gerrit.wikimedia.org/r/c/mediawiki/extensions/CodeMirror/+/1059166

Proper dark mode styles are now ready for review: https://gerrit.wikimedia.org/r/c/mediawiki/extensions/CodeMirror/+/1059166

Can we test this on a Patch Demo? Not sure which settings are required for Vector dark mode...

Sure!

I've added links and notes to the "Patch Demo" section of the task description.

Need to do contrast checks. Also, what about the WMDE color adjustments that are on some wikis but not fleetwide?

Need to do contrast checks.

The latest is now on Patch Demo. See what you think. Links (that I will keep updated) are in the "Patch Demo" section of the task description.

Using the WCAG Color Contrast tool as recommend on mediawiki.org, CodeMirror is now compliant with WCAH 2.0 AA in both light and dark mode, with a few exceptions:

  • Some non-printable characters (often inserted by accident) get color-destructive--hover instead of color-destructive to make it more attention-grabbing
  • Non-breaking spaces are highlighted with color-placeholder, which is fine in light mode, but just a tad bit too dark against a dark background. It is not meant to be very visible, so I'm going to ignore this one.

I think that's it. These two scenarios should rarely be encountered in the wild.

Also, what about the WMDE color adjustments that are on some wikis but not fleetwide?

I have not touched it. Using the same WCAG Color Contrast tool, I see these colors do not pass WCAG AA checks in light or dark mode, but I'm not sure if they're supposed to as they're specifically designed for colorblind people. I'd prefer to leave any changes to those colors to WMDE.

Change #1059166 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] Implement dark mode styles and use Codex CSS components in search panel

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

Probably doesn't need extensive QA given how many eyes have tested this, including against contrast checkers, but please do your thing :)

Note the new search panel was included as part of this (T371436) because the default CodeMirror search panel isn't dark mode compatible. QA efforts for the new search panel can be reserved for T371436: Redesign CodeMirror search panel, which is still waiting on another patch to be merged as of the time of writing.

New colors (applies to all wikis) and a new search panel (mediawiki.org, hewiki, and soon to be all of group0) I think warrants a Tech News announcement. I'll add something for this, T371436, and the group0 deployment (T357795), all of which are aimed for next week.

@MusikAnimal Are you supposed to enable both syntax highlighting or am I supposed to use just "Use colorblind-friendly scheme? When checking both, you can see in the source editing gif, I get a failed to load data blob error. If I switch to visual editor, I get "The specified page ($1) does not exist:.

*Status: ❌ FAIL
Environment: Beta
OS: macOS Sonoma 14.6.1
Browser: Chrome 128
Device: MBA
Emulated Device:** NA

Test Artifact(s):

Test Steps
  1. Visit Special:Preferences and enable syntax highlighting (Color blind friendly).
  2. Enable dark mode.
  3. Click on "Edit source"
  4. Activate "Syntax highlighting"

❌ AC1: Confirm that the syntax highlighting is functional. Confirm that the colors are compatible with dark mode. Confirm that all text is legible.

Source EditingVisual Source
2024-09-03_14-09-56.mp4.gif (616×750 px, 3 MB)
2024-09-03_14-13-56.png (569×747 px, 102 KB)

MusikAnimal Are you supposed to enable both syntax highlighting or am I supposed to use just "Use colorblind-friendly scheme? When checking both, you can see in the source editing gif, I get a failed to load data blob error.

I don't know why Realtime Preview is failing here – it's probably just Beta being slow as usual :-P Either way, it has no relation to this task, so you can just disable it by clicking "Preview" at the top-right.

If I switch to visual editor, I get "The specified page ($1) does not exist:.

Also not sure what this is, but it has nothing to do with CodeMirror.

https://en.wikipedia.beta.wmflabs.org/wiki/Star_Wars shows an error when trying to read the page, so for sure something is wonky on Beta! I am however somehow able to edit it.

If it helps, you're welcome to use the Patch Demo links for QA instead:

To be clear, we're looking only for glaring issues regarding the syntax highlighting of wikitext in dark mode. Any issue seen with other UI components is unrelated.

(There is also the new search panel, but we can save QA efforts for that for T371436. Dark mode for the new search panel should work fine as it's 100% Codex components, so I'm not asking to QA that here)

Noting https://patchdemo.wmcloud.org/wikis/e9aed027c3/wiki/CodeMirror?veaction=editsource&useskin=vector-2022&vectornightmode=1&cm6enable=1 sometimes doesn't load CodeMirror at all… that's a race condition (still unrelated to this task). I'll get a fix in, but if you encounter this issue just keep refreshing and it should eventually work.

Apologies for all of the confusion!

@MusikAnimal Beta definitely gets wonky at times. Thanks for the links! As seen from the gifs below, I did not encounter any issues with the syntax highlighting of wikitext in dark mode. I will move this to Done, thanks for all your work!

*Status: ✅ PASS
Environment: Patch Demo
OS: macOS Sonoma 14.6.1
Browser: Chrome 128
Device: MBA
Emulated Device:** NA

Test Artifact(s):

Test Steps
  1. Visit Special:Preferences and enable syntax highlighting (Color blind friendly).
  2. Enable dark mode.
  3. Click on "Edit source"
  4. Activate "Syntax highlighting"

✅ AC1: Confirm that the syntax highlighting is functional. Confirm that the colors are compatible with dark mode. Confirm that all text is legible.

CodeMirror 5 + WikiEditor: https://patchdemo.wmcloud.org/wikis/4226970e0f/wiki/CodeMirror?action=edit&useskin=vector-2022&vectornightmode=1

2024-09-04_15-31-59.mp4.gif (526×1 px, 845 KB)

CodeMirror 6 + WikiEditor: https://patchdemo.wmcloud.org/wikis/4226970e0f/wiki/CodeMirror?action=edit&useskin=vector-2022&vectornightmode=1&cm6enable=1

2024-09-04_15-32-50.mp4.gif (518×1 px, 1 MB)

CodeMirror 5 + 2017 editor: https://patchdemo.wmcloud.org/wikis/4226970e0f/wiki/CodeMirror?veaction=editsource&useskin=vector-2022&vectornightmode=1

2024-09-04_15-34-55.mp4.gif (740×992 px, 1 MB)

CodeMirror 6 + 2017 editor: https://patchdemo.wmcloud.org/wikis/4226970e0f/wiki/CodeMirror?veaction=editsource&useskin=vector-2022&vectornightmode=1&cm6enable=1

2024-09-04_15-35-30.mp4.gif (752×980 px, 793 KB)