CodeMirror: make bracket matching match CJK full-width brackets

This is only done for wikitext because CJK brackets can cause unexpected
errors in other languages.

Bug: T362992
Change-Id: Icf98e8fd7e0392845df2e3b7d3201e7f94f95a3f
This commit is contained in:
MusikAnimal 2024-04-19 15:26:38 -04:00
parent a21aa79e2d
commit 0e5fe342d9
2 changed files with 17 additions and 2 deletions

File diff suppressed because one or more lines are too long

View file

@ -82,7 +82,7 @@ class CodeMirror {
this.specialCharsExtension,
this.heightExtension,
this.updateExtension,
bracketMatching(),
this.bracketMatchingExtension,
EditorState.readOnly.of( this.readOnly ),
EditorView.domEventHandlers( {
blur: () => this.$textarea.triggerHandler( 'blur' ),
@ -117,6 +117,21 @@ class CodeMirror {
return extensions;
}
/**
* This extension adds bracket matching to the CodeMirror editor.
*
* @return {Extension}
*/
get bracketMatchingExtension() {
return bracketMatching( mw.config.get( 'wgPageContentModel' ) === 'wikitext' ?
{
// Also match CJK full-width brackets (T362992)
// This is only for wikitext as it can be confusing in programming languages.
brackets: '()[]{}()【】[]{}'
} : {}
);
}
/**
* This extension listens for changes in the CodeMirror editor and fires
* the `ext.CodeMirror.input` hook with the {@link ViewUpdate} object.