mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeMirror
synced 2024-12-12 14:25:06 +00:00
925775778a
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
94 lines
2.5 KiB
JavaScript
94 lines
2.5 KiB
JavaScript
/**
|
|
* VisualEditor UserInterface CodeMirror tool.
|
|
*
|
|
* @class
|
|
* @abstract
|
|
* @extends ve.ui.Tool
|
|
* @constructor
|
|
* @param {OO.ui.ToolGroup} toolGroup
|
|
* @param {Object} [config] Configuration options
|
|
*/
|
|
ve.ui.CodeMirrorTool = function VeUiCodeMirrorTool() {
|
|
// Parent constructor
|
|
ve.ui.CodeMirrorTool.super.apply( this, arguments );
|
|
|
|
this.extCodeMirror = require( 'ext.CodeMirror.v6' );
|
|
|
|
// Events
|
|
this.toolbar.connect( this, { surfaceChange: 'onSurfaceChange' } );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
OO.inheritClass( ve.ui.CodeMirrorTool, ve.ui.Tool );
|
|
|
|
/* Static properties */
|
|
|
|
ve.ui.CodeMirrorTool.static.name = 'codeMirror';
|
|
ve.ui.CodeMirrorTool.static.autoAddToCatchall = false;
|
|
ve.ui.CodeMirrorTool.static.title = OO.ui.deferMsg( 'codemirror-toggle-label' );
|
|
ve.ui.CodeMirrorTool.static.icon = 'highlight';
|
|
ve.ui.CodeMirrorTool.static.group = 'utility';
|
|
ve.ui.CodeMirrorTool.static.commandName = 'codeMirror';
|
|
ve.ui.CodeMirrorTool.static.deactivateOnSelect = false;
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
ve.ui.CodeMirrorTool.prototype.onSelect = function () {
|
|
// Parent method
|
|
ve.ui.CodeMirrorTool.super.prototype.onSelect.apply( this, arguments );
|
|
|
|
const useCodeMirror = !!this.toolbar.surface.mirror;
|
|
this.setActive( useCodeMirror );
|
|
|
|
this.extCodeMirror.setCodeMirrorPreference( useCodeMirror );
|
|
this.extCodeMirror.logUsage( {
|
|
editor: 'wikitext-2017',
|
|
enabled: useCodeMirror,
|
|
toggled: true,
|
|
// eslint-disable-next-line camelcase
|
|
edit_start_ts_ms: ( this.toolbar.target.startTimeStamp * 1000 ) || 0
|
|
} );
|
|
};
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
ve.ui.CodeMirrorTool.prototype.onSurfaceChange = function ( oldSurface, newSurface ) {
|
|
const isDisabled = newSurface.getMode() !== 'source';
|
|
|
|
this.setDisabled( isDisabled );
|
|
if ( !isDisabled ) {
|
|
const command = this.getCommand();
|
|
const surface = this.toolbar.getSurface();
|
|
const useCodeMirror = mw.user.options.get( 'usecodemirror' ) > 0;
|
|
command.execute( surface, [ useCodeMirror ] );
|
|
this.setActive( useCodeMirror );
|
|
|
|
if ( this.toolbar.target.startTimeStamp ) {
|
|
this.extCodeMirror.logUsage( {
|
|
editor: 'wikitext-2017',
|
|
enabled: useCodeMirror,
|
|
toggled: false,
|
|
// eslint-disable-next-line camelcase
|
|
edit_start_ts_ms: ( this.toolbar.target.startTimeStamp * 1000 ) || 0
|
|
} );
|
|
}
|
|
}
|
|
};
|
|
|
|
ve.ui.CodeMirrorTool.prototype.onUpdateState = function () {};
|
|
|
|
/* Registration */
|
|
|
|
ve.ui.toolFactory.register( ve.ui.CodeMirrorTool );
|
|
|
|
/* Command */
|
|
|
|
ve.ui.commandRegistry.register(
|
|
new ve.ui.Command(
|
|
'codeMirror', 'codeMirror', 'toggle'
|
|
)
|
|
);
|