mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeMirror
synced 2024-12-12 06:15:27 +00:00
mediaWikiLang: remove used hook handlers
Every time when `mediaWikiLang()` is called, a new handler is registered for the hook `ext.CodeMirror.ready`. This causes unexpected errors, so the used handler needs to be removed before registering a new handler. Bug: T380840 Change-Id: I81bed58ec37a508e53a93895c7e20de358a658e0
This commit is contained in:
parent
4647e415d5
commit
60f450a773
|
@ -1374,6 +1374,8 @@ class CodeMirrorModeMediaWiki {
|
|||
}
|
||||
}
|
||||
|
||||
let handler;
|
||||
|
||||
/**
|
||||
* Gets a LanguageSupport instance for the MediaWiki mode.
|
||||
*
|
||||
|
@ -1401,7 +1403,10 @@ const mediaWikiLang = ( config = { bidiIsolation: false }, mwConfig = null ) =>
|
|||
|
||||
// Register MW-specific Extensions into CodeMirror preferences. Whether they are enabled
|
||||
// or not is determined by the user's preferences and wiki configuration.
|
||||
mw.hook( 'ext.CodeMirror.ready' ).add( ( $textarea, cm ) => {
|
||||
if ( handler ) {
|
||||
mw.hook( 'ext.CodeMirror.ready' ).remove( handler );
|
||||
}
|
||||
handler = ( $textarea, cm ) => {
|
||||
if ( config.templateFolding !== false ) {
|
||||
cm.preferences.registerExtension( 'templateFolding', templateFoldingExtension, cm.view );
|
||||
}
|
||||
|
@ -1411,7 +1416,8 @@ const mediaWikiLang = ( config = { bidiIsolation: false }, mwConfig = null ) =>
|
|||
if ( config.bidiIsolation ) {
|
||||
cm.preferences.registerExtension( 'bidiIsolation', bidiIsolationExtension, cm.view );
|
||||
}
|
||||
} );
|
||||
};
|
||||
mw.hook( 'ext.CodeMirror.ready' ).add( handler );
|
||||
|
||||
return new LanguageSupport( lang, langExtension );
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue