mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeMirror
synced 2025-01-06 01:35:39 +00:00
Merge "CodeMirrorWikiEditor: properly manage WikiEditor buttons"
This commit is contained in:
commit
aef9282422
|
@ -56,10 +56,16 @@ class CodeMirrorWikiEditor extends CodeMirror {
|
||||||
* @type {Function|null}
|
* @type {Function|null}
|
||||||
*/
|
*/
|
||||||
this.realtimePreviewHandler = null;
|
this.realtimePreviewHandler = null;
|
||||||
|
/**
|
||||||
|
* The WikiEditor search button, which is usurped to open the CodeMirror search panel.
|
||||||
|
*
|
||||||
|
* @type {jQuery|null}
|
||||||
|
*/
|
||||||
|
this.$searchBtn = null;
|
||||||
/**
|
/**
|
||||||
* The old WikiEditor search button, to be restored if CodeMirror is disabled.
|
* The old WikiEditor search button, to be restored if CodeMirror is disabled.
|
||||||
*
|
*
|
||||||
* @type {jQuery}
|
* @type {jQuery|null}
|
||||||
*/
|
*/
|
||||||
this.$oldSearchBtn = null;
|
this.$oldSearchBtn = null;
|
||||||
}
|
}
|
||||||
|
@ -127,9 +133,10 @@ class CodeMirrorWikiEditor extends CodeMirror {
|
||||||
// Hijack the search button to open the CodeMirror search panel
|
// Hijack the search button to open the CodeMirror search panel
|
||||||
// instead of the WikiEditor search dialog.
|
// instead of the WikiEditor search dialog.
|
||||||
// eslint-disable-next-line no-jquery/no-global-selector
|
// eslint-disable-next-line no-jquery/no-global-selector
|
||||||
const $searchBtn = $( '.wikiEditor-ui .group-search a' );
|
this.$searchBtn = $( '.wikiEditor-ui .group-search .tool' );
|
||||||
this.$oldSearchBtn = $searchBtn.clone( true );
|
this.$oldSearchBtn = this.$searchBtn.clone( true );
|
||||||
$searchBtn.off( 'click keydown keypress' )
|
this.$searchBtn.find( 'a' )
|
||||||
|
.off( 'click keydown keypress' )
|
||||||
.on( 'click keydown', ( e ) => {
|
.on( 'click keydown', ( e ) => {
|
||||||
if ( e.type === 'click' || ( e.type === 'keydown' && e.key === 'Enter' ) ) {
|
if ( e.type === 'click' || ( e.type === 'keydown' && e.key === 'Enter' ) ) {
|
||||||
openSearchPanel( this.view );
|
openSearchPanel( this.view );
|
||||||
|
@ -143,7 +150,7 @@ class CodeMirrorWikiEditor extends CodeMirror {
|
||||||
{
|
{
|
||||||
section: 'advanced',
|
section: 'advanced',
|
||||||
groups: {
|
groups: {
|
||||||
search: {
|
codemirror: {
|
||||||
tools: {
|
tools: {
|
||||||
CodeMirrorPreferences: {
|
CodeMirrorPreferences: {
|
||||||
type: 'element',
|
type: 'element',
|
||||||
|
@ -152,7 +159,7 @@ class CodeMirrorWikiEditor extends CodeMirror {
|
||||||
title: mw.msg( 'codemirror-prefs-title' ),
|
title: mw.msg( 'codemirror-prefs-title' ),
|
||||||
icon: 'settings',
|
icon: 'settings',
|
||||||
framed: false,
|
framed: false,
|
||||||
classes: [ 'tool', 'cm-mw-settings' ]
|
classes: [ 'tool' ]
|
||||||
} );
|
} );
|
||||||
button.on( 'click',
|
button.on( 'click',
|
||||||
() => this.preferences.toggle( this.view, true )
|
() => this.preferences.toggle( this.view, true )
|
||||||
|
@ -285,8 +292,11 @@ 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
|
this.$searchBtn.replaceWith( this.$oldSearchBtn );
|
||||||
$( '.wikiEditor-ui .group-search a' ).replaceWith( this.$oldSearchBtn );
|
this.$textarea.wikiEditor( 'removeFromToolbar', {
|
||||||
|
section: 'advanced',
|
||||||
|
group: 'codemirror'
|
||||||
|
} );
|
||||||
mw.hook( 'ext.CodeMirror.switch' ).fire( false, this.$textarea );
|
mw.hook( 'ext.CodeMirror.switch' ).fire( false, this.$textarea );
|
||||||
} else {
|
} else {
|
||||||
this.enableCodeMirror();
|
this.enableCodeMirror();
|
||||||
|
|
|
@ -6,6 +6,13 @@
|
||||||
border: inherit;
|
border: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mimics .group-search
|
||||||
|
.wikiEditor-ui-toolbar .group-codemirror {
|
||||||
|
float: right;
|
||||||
|
border-right: 0;
|
||||||
|
border-left: @border-subtle;
|
||||||
|
}
|
||||||
|
|
||||||
.cm-mw-toggle-wikieditor {
|
.cm-mw-toggle-wikieditor {
|
||||||
.oo-ui-icon-syntax-highlight {
|
.oo-ui-icon-syntax-highlight {
|
||||||
background-color: @color-base;
|
background-color: @color-base;
|
||||||
|
|
Loading…
Reference in a new issue