Page MenuHomePhabricator

WikiEditor formatting keyboard shortcuts are being triggered in non-wikitext modes
Closed, ResolvedPublicBUG REPORT

Description

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

What happens?:

The wikitext-specific keyboard shortcuts work.

What should have happened instead?:

They shouldn't work, since we're not editing wikitext.

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

The bubbling of events to the native textarea was added in r1129024 as a means to make CodeMirror integration easier. It was mentioned that this could bit us down the road, and here we are :-P

Ideally the fix would be in WikiEditor (2010). It should probably have knowledge of non-wikitext and react accordingly. Both CodeMirror and CodeEditor use CSS hacks to hide the irrelevant buttons from the toolbar. Related: T47850.

I was not able to figure out why this bug is not present in CodeEditor. I suspect Ace doesn't bubble any keystrokes.

That said, disabling the CodeMirror-to-textarea event bubbling for non-wikitext is probably the safest thing to do, but one of the goals is for all modes/content models is to be treated the same, and this would deviate from that. Maybe that's OK, as there aren't many integrations with non-wikitext to begin with.

Event Timeline

T47850 got me thinking that maybe we should nip this in the bud and remove WikiEditor support entirely for non-wikitext? The current state of affairs is that WikiEditor very much assumes wikitext, and really all it's giving us is the toolbar. I can make a toolbar.

We don't want to remove WikiEditor for CodeMirror+wikitext as there are too many WikiEditor integrations. The same surely can't be said for non-wikitext. I think the CSS hack that CodeMirror and CodeEditor use probably prohibit most integrations from working.

I think this one is actually a really big bug, which might not be described correctly and in total above? It may be difficult to break this down into smaller tasks that can be fixed individually. Or the following may need a parent task, as this is going on about keyboard shortcuts?

Here's what I think:

  • CodeEditor should be automatically toggled on any page that's code (CSS, JS, Scribunto) or simply plain text.
  • The 5 wikitext elements on the main toolbar (bold, italic, link, media, references) and all those under “advanced” are useless clutter and should not be present on non-wikitext pages
  • However, the “special characters” and “help” elements may be useful whatever the language, and should be part of the CodeEditor toolbar.

Additionally, some language-specific elements might be useful:

  • Creating JavaScript redirects (which work differently to WikiText redirects)
  • Inserting comments into code.

I think this one is actually a really big bug, which might not be described correctly and in total above? It may be difficult to break this down into smaller tasks that can be fixed individually. Or the following may need a parent task, as this is going on about keyboard shortcuts?

CodeEditor

Before we go any further, let me make it clear this is about MediaWiki-extensions-CodeMirror, not CodeEditor. But assuming you did mean to say CodeMirror,

  • should be automatically toggled on any page that's code (CSS, JS, Scribunto) or simply plain text.
  • The 5 wikitext elements on the main toolbar (bold, italic, link, media, references) and all those under “advanced” are useless clutter and should not be present on non-wikitext pages

This is already the case.

  • However, the “special characters” and “help” elements may be useful whatever the language, and should be part of the toolbar.

Typically non-wikitext is treated as code, which rarely contains diacritics or otherwise "special" characters. The "Help" panel as written currently appears to only be for wikitext. Either way both of those are from WikiEditor, so I'm inclined to hide them as WikiEditor doesn't know about non-wikitext (which is why I tagged it). But any such change to WikiEditor should probably be a different task, sorry. I've removed the tag.

Additionally, some language-specific elements might be useful:

  • Creating JavaScript redirects (which work differently to WikiText redirects)

Do you mean a code snippet to do i.e. window.location.replace() or something similar? That seems rather niche. However, adding support for customizable snippets would be very cool! We could make it site configuration so specific projects can provide commonly needed snippets, etc.

  • Inserting comments into code.

A button to add or even toggle comments is doable, and I see there are suitable icons in Codex. We can look into it!

For the issue at hand (wikitext-specific keyboard shortcuts working where they shouldn't), I'm thinking of going with a quick fix for now to simply disable CodeMirror-to-textarea event bubbling for non-wikitext.

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

[mediawiki/extensions/CodeMirror@master] CodeMirror: disable event bubbling to the textarea for non-wikitext

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

MusikAnimal changed the task status from Open to In Progress.Aug 13 2025, 6:14 PM
MusikAnimal claimed this task.

Change #1178593 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] CodeMirror: disable keydown events on textarea for non-wikitext

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

MusikAnimal moved this task from Bugs to Done on the MediaWiki-extensions-CodeMirror board.

I'm calling this resolved. I'll create a new task to explore creating our own toolbar, and removing the WikiEditor dependency entirely for non-wikitext, but I will wait to see how the current implementation is received before doing that. It is still unclear how many integrations there are for WikiEditor and non-wikitext.