From c873f9d9fa775663456af85e17cbe19a832c5403 Mon Sep 17 00:00:00 2001 From: MusikAnimal Date: Mon, 29 Apr 2024 15:26:11 -0400 Subject: [PATCH] ext.CodeMirror.visualEditor: don't load on RTL pages CodeMirror 5 does not work on RTL pages. This commit does a crude check of the `dir` attribute of `.mw-body-content .mw-parser-output` because the VisualEditor surface and even the native textarea isn't available when the module is first loaded. Bug: T363752 Change-Id: If3825d6e5467d2bcff2d83e838081bf041243920 --- .../modules/ve-cm/ve.ui.CodeMirrorAction.js | 5 ++++- .../modules/ve-cm/ve.ui.CodeMirrorTool.js | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/resources/modules/ve-cm/ve.ui.CodeMirrorAction.js b/resources/modules/ve-cm/ve.ui.CodeMirrorAction.js index 13c33b03..5b3d99de 100644 --- a/resources/modules/ve-cm/ve.ui.CodeMirrorAction.js +++ b/resources/modules/ve-cm/ve.ui.CodeMirrorAction.js @@ -277,4 +277,7 @@ ve.ui.CodeMirrorAction.prototype.getPosFromOffset = function ( veOffset ) { /* Registration */ -ve.ui.actionFactory.register( ve.ui.CodeMirrorAction ); +// eslint-disable-next-line no-jquery/no-global-selector +if ( $( '.mw-body-content .mw-parser-output' ).attr( 'dir' ) === 'ltr' ) { + ve.ui.actionFactory.register( ve.ui.CodeMirrorAction ); +} diff --git a/resources/modules/ve-cm/ve.ui.CodeMirrorTool.js b/resources/modules/ve-cm/ve.ui.CodeMirrorTool.js index fe7d8942..ea23c29d 100644 --- a/resources/modules/ve-cm/ve.ui.CodeMirrorTool.js +++ b/resources/modules/ve-cm/ve.ui.CodeMirrorTool.js @@ -82,14 +82,17 @@ ve.ui.CodeMirrorTool.prototype.onSurfaceChange = function ( oldSurface, newSurfa ve.ui.CodeMirrorTool.prototype.onUpdateState = function () {}; -/* Registration */ +// eslint-disable-next-line no-jquery/no-global-selector +if ( $( '.mw-body-content .mw-parser-output' ).attr( 'dir' ) === 'ltr' ) { + /* Registration */ -ve.ui.toolFactory.register( ve.ui.CodeMirrorTool ); + ve.ui.toolFactory.register( ve.ui.CodeMirrorTool ); -/* Command */ + /* Command */ -ve.ui.commandRegistry.register( - new ve.ui.Command( - 'codeMirror', 'codeMirror', 'toggle' - ) -); + ve.ui.commandRegistry.register( + new ve.ui.Command( + 'codeMirror', 'codeMirror', 'toggle' + ) + ); +}