Commit graph

7 commits

Author SHA1 Message Date
bhsd 197b5649ff CodeMirrorModeMediaWiki: autocompletion
Autocomplete magic words, tag names and url protocols. This patch also enables block comment using `<!-- -->`.

Bug: T95100
Change-Id: If37da956ac1eb945b96753e6728c0247b1a68b66
2024-11-19 16:02:35 +08:00
MusikAnimal 13c9eae26e CodeMirrorPreferences: add panel to tweak prefs with the editor open
This is toggled by pressing Mod-Shift-, (or Command-Shift-, on MacOS),
which then puts focus on the preferences panel. It can be closed with
the Escape key, just like other CM panels.

The CodeMirror class comes with these extension which can be toggled in
preferences:
* Bracket matching
* Line numbering
* Line wrapping
* Highlight the active line
* Show special characters

Only bracket matching, line numbering, and line wrapping are available
in the 2017 editor.

The bidi isolation and template folding extensions are registered in
CodeMirrorModeMediaWiki as they are MW-specific. CodeMirrorPreferences'
new registerExtension() method allows any consumer of CodeMirror to add
any arbitrary extensions to the preferences panel. This is expected to
be called *after* CodeMirror has finished initializing. The
'ext.CodeMirror.ready' hook now passes the CodeMirror instance to
accommodate this.

The preferences are stored as a single user option in the database,
called 'codemirror-preferences'. The defaults can be configured with the
$wgCodeMirrorDefaultPreferences configuration setting. The
sysadmin-facing values are the familiar boolean, but since CodeMirror is
widely used, we make extra efforts to reduce the storage footprint (see
T54777). This includes only storing preferences that differ from the
defaults, and using binary representation instead of boolean values,
since the user option is stored as a string.

For now, all preferences are ignored in the 2017 editor. In a future
patch, we may add some as toggleable Tools in the VE toolbar.

Other changes:
* Refactor CSS to use a .darkmode() mixin
* Add a method to create a CSS-only fieldset in CodeMirrorPanel
* Fix Jest tests now that there are more calls to mw.user.options.get()
* Adjust Selenium tests to always use CM6
* Adjust Selenium tests to delete test pages (useful for local dev)
* Remove unused code

Bug: T359498
Change-Id: I70dcf2f49418cea632c452c1266440effad634f3
2024-11-18 22:23:22 -05:00
Umherirrender 75428fa046 Use namespaced classes
Changes to the use statements done automatically via script

Change-Id: Ic474721ccdb77614f46b0237251927e04b2f183d
2024-10-19 23:29:39 +02:00
MusikAnimal b27c9843b5 Remove $wgCodeMirrorRTL as redundant config setting
This was introduced in Iac30ffe274 to control the rollout of CM6 to RTL
wikis separately from LTR wikis because of various bugs. While RTL still
isn't perfect, it is stable enough now (hewiki has not complained) and
the 2017 editor is also fully supported. Thus, we no longer need this
feature flag.

Bug: T170001
Change-Id: Ia439527aaab07644b358cedf9603cd9d148b6608
2024-08-30 22:03:07 +00:00
bhsd 925775778a CodeMirror 6 for VE 2017 wikitext editor
Add new temporary ext.CodeMirror.visualEditor.init RL module which
selects the temporary ext.CodeMirror.visualEditor.v6 or non-v6 based on
$wgCodeMirrorV6. This will allow us to deploy CM6 further.

As a result of this work, the core CodeMirror class now has knowledge
of ve.ui.Surface.

Other changes:
* Add Compartment for specialCharsExtension so it can be disabled in VE.
* Add option to mediaWikiLang() to disable template folding.
* Add support for RTL wikis where $wgCodeMirrorRTL is enabled.
* Make CodeMirror.logUsage() and setCodeMirrorPreference() static.
* Fix unit and linting tests.

Some code courtesy of Fandom, GPLv2-or-later; see:
https://github.com/Wikia/mediawiki-extensions-CodeMirror/commit/ef297c48c

Bug: T357482
Change-Id: I15453b33e77e1c1b4d5e5183e41e53d56ff14c3e
2024-08-01 03:15:21 -04:00
MusikAnimal 7e9d90bb52 CM6: put template folding behind feature flag and rework config settings
Template folding is likely going to be a big 'hit' of a feature, but not
everyone will want it. Until CodeMirror prefs are introduced (T359498),
we need a way to control the rollout of template folding. This commit
adds $wgCodeMirrorTemplateFoldingNamespaces which acts similar to the
existing $wgCodeMirrorLineNumberingNamespaces.

We also move template folding to be part of CodeMirrorModeMediaWiki,
since the feature is unique to MediaWiki wikitext.

Move configuration settings to be part of the DataScript, thus removing
the need for the ResourceLoaderGetConfigVarsHook (which unnecessarily
makes the config settings available on every page load).

Other minor changes like adding missing JSDoc blocks.

Bug: T30684
Change-Id: I67518c0968f64c79e290f57b4884d30a161212d3
2024-03-14 23:54:39 -04:00
Tim Starling 7a3f46b490 Migrate ResourceLoaderCodeMirrorModule to a virtual file callback
Bug: T47514
Depends-On: I97d61b5793159cea365740e0563f7b733e0f16de
Change-Id: I31b80fc1c7701fc1075d655270706e341942415d
2023-05-05 16:26:09 +10:00
Renamed from includes/ResourceLoaderCodeMirrorModule.php (Browse further)