Merge "CodeMirrorWikiEditor: make WikiEditor search button open CM search panel"

This commit is contained in:
jenkins-bot 2024-09-03 15:59:18 +00:00 committed by Gerrit Code Review
commit 87daa30df0

View file

@ -2,7 +2,8 @@ const {
EditorSelection, EditorSelection,
EditorView, EditorView,
Extension, Extension,
LanguageSupport LanguageSupport,
openSearchPanel
} = require( 'ext.CodeMirror.v6.lib' ); } = require( 'ext.CodeMirror.v6.lib' );
const CodeMirror = require( 'ext.CodeMirror.v6' ); const CodeMirror = require( 'ext.CodeMirror.v6' );
@ -55,6 +56,12 @@ class CodeMirrorWikiEditor extends CodeMirror {
* @type {Function|null} * @type {Function|null}
*/ */
this.realtimePreviewHandler = null; this.realtimePreviewHandler = null;
/**
* The old WikiEditor search button, to be restored if CodeMirror is disabled.
*
* @type {jQuery}
*/
this.$oldSearchBtn = null;
} }
/** /**
@ -117,6 +124,19 @@ class CodeMirrorWikiEditor extends CodeMirror {
this.view.focus(); this.view.focus();
} }
// Hijack the search button to open the CodeMirror search panel
// instead of the WikiEditor search dialog.
// eslint-disable-next-line no-jquery/no-global-selector
const $searchBtn = $( '.wikiEditor-ui .group-search a' );
this.$oldSearchBtn = $searchBtn.clone( true );
$searchBtn.off( 'click keydown keypress' )
.on( 'click keydown', ( e ) => {
if ( e.type === 'click' || ( e.type === 'keydown' && e.key === 'Enter' ) ) {
openSearchPanel( this.view );
e.preventDefault();
}
} );
/** /**
* Called after CodeMirror is enabled or disabled in WikiEditor. * Called after CodeMirror is enabled or disabled in WikiEditor.
* *
@ -234,6 +254,8 @@ class CodeMirrorWikiEditor extends CodeMirror {
if ( this.view ) { if ( this.view ) {
this.setCodeMirrorPreference( false ); this.setCodeMirrorPreference( false );
this.destroy(); this.destroy();
// eslint-disable-next-line no-jquery/no-global-selector
$( '.wikiEditor-ui .group-search a' ).replaceWith( this.$oldSearchBtn );
mw.hook( 'ext.CodeMirror.switch' ).fire( false, this.$textarea ); mw.hook( 'ext.CodeMirror.switch' ).fire( false, this.$textarea );
} else { } else {
this.enableCodeMirror(); this.enableCodeMirror();