Page MenuHomePhabricator

2017 wikitext editor integration in CodeMirror 6
Open, LowPublic

Description

Background

With CodeMirror 5, the CodeMirror object is in the global scope, making it simple for extensions to integrate with it. The 2017 wikitext editor (part of VisualEditor) does this with ve.ui.CodeMirrorAction.js and ve.ui.CodeMirrorTool.js, which live in MediaWiki-extensions-CodeMirror and registered as a PluginModule for VisualEditor. This needs to be migrated to work with CodeMirror 6.

Acceptance criteria

  • Introduce new ext.CodeMirror.v6.visualEditor module which gets loaded on wikis with $wgCodeMirrorV6
  • Feature parity is not there with non-VE CodeMirror, but this is apparently expected (?)

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

I'm happy to take a stab at the ES6 rewrite, but would love to hear any thoughts from the Editing team before diving in. I may need a fair amount of assistance, too, as my knowledge of VE internals is quite limited.

How about exposing a global CM6 constructor from one RL module? Then all other modules (2003 editor/2010 editor/2017 editor) can easily depend on this module just like ext.CodeMirror.lib.

How about exposing a global CM6 constructor from one RL module? Then all other modules (2003 editor/2010 editor/2017 editor) can easily depend on this module just like ext.CodeMirror.lib.

Something like that would be most ideal, yes. However I'm struggling to find a clean solution. The main problem is we can't mix ECMAScript Modules with CommonJS-style modules, so a true global CodeMirror object (or maybe bound to mw.CodeMirror or something) is seemingly the only way to do it. Ideally we'd be able to do something like this:

mw.loader.using( [ 'ext.CodeMirror.v6` ], ( require ) => {
    const CodeMirror = require( 'ext.CodeMirror.v6` );
    …
} );

but we can't use module.exports in the source. We could have an additional wrapper just for ResourceLoader, still packaged as ext.CodeMirror.v6. We'd need to something similar for the mediawiki mode, and similar for others. It gets messy!

Solving this problem is basically the last chunk of work left. I'm going to make it my focus this week. I'd still love to hear any thoughts from the Editing team, if they have any.

MusikAnimal changed the task status from Open to Stalled.Mar 14 2024, 9:36 PM

Following T214989, we can load CodeMirror in much the same way as before. This may make migrating the 2017 editor integration considerably easier. I'm going to stall this task until that work is complete.

MusikAnimal changed the task status from Stalled to Open.Tue, Apr 30, 7:25 PM

Not stalled anymore. We're basically at the point where I think we could use the ResourceLoader modules just like we did before, only they're different modules now and there's a few CodeMirror API things that need updating.

I will take a stab at this at some point, if the editing team doesn't beat me to it.

As it turns out, the engineers at Fandom have been working on this. They have it almost done: https://github.com/Wikia/mediawiki-extensions-CodeMirror/tree/15720baabe885966aa3329394665f5882ebeb7c8/resources/modules/ve-cm

They said they have plans to upstream it to CodeMirror :) Yay!

MusikAnimal changed the task status from Open to Stalled.Fri, May 3, 8:50 AM

Stalling just to reserve this for the Fandom engineers. As I told them, I'm happy to upstream their code myself, but I wanted to give them room to do in case they want to preserve attribution. (Their fork is MW 1.39 and may not cherry-pick cleanly)

MusikAnimal changed the task status from Stalled to Open.Tue, May 14, 9:47 PM
MusikAnimal claimed this task.

Haven't heard back from them so I'm going to work on this now.

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

[mediawiki/extensions/CodeMirror@master] [WIP] CodeMirror 6 for VE 2017 wikitext editor

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