mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeMirror
synced 2024-12-19 09:10:39 +00:00
00f947e97f
The extension is custom built for MediaWiki (i.e. handling of extension tags like <ref> that aren't HTML tags), so it only makes sense to bundle it as part of the MediaWiki language mode. Resultantly, we can no longer check the direction of the textarea where we enable bidi isolation, because the language mode should have no knowledge of the textarea. Instead we offer a `config` object (akin to other language modes offered by CodeMirror), with currently only one option: `bidiIsolation`. It is the responsibility of the caller to enable this where desired. Also make templateFolding and CodeMirrorModeMediaWiki use `export default` since they both only export one thing. This commit is in preparation for Ide716247e5, where we need bidi isolation separated from the CodeMirror class due to its dependency on CodeMirrorModeMediaConfig. Bug: T358804 Bug: T214989 Change-Id: If3211bd259bd7833919a627faabd86ae7aa81b53
39 lines
1.4 KiB
JavaScript
39 lines
1.4 KiB
JavaScript
import CodeMirror from '../../src/codemirror.js';
|
|
import mediaWikiLang from '../../src/codemirror.mode.mediawiki.js';
|
|
|
|
const testCases = [
|
|
{
|
|
title: 'wraps HTML tags with span.cm-bidi-isolate',
|
|
input: 'שלום<span class="foobar">שלום</span>שלום',
|
|
output: '<div class="cm-line">שלום<span class="cm-bidi-isolate"><span class="cm-mw-htmltag-bracket"><</span><span class="cm-mw-htmltag-name">span </span><span class="cm-mw-htmltag-attribute">class="foobar"</span><span class="cm-mw-htmltag-bracket">></span></span>שלום<span class="cm-bidi-isolate"><span class="cm-mw-htmltag-bracket"></</span><span class="cm-mw-htmltag-name">span</span><span class="cm-mw-htmltag-bracket">></span></span>שלום</div>'
|
|
}
|
|
];
|
|
|
|
// Setup CodeMirror instance.
|
|
const textarea = document.createElement( 'textarea' );
|
|
textarea.dir = 'rtl';
|
|
document.body.appendChild( textarea );
|
|
const cm = new CodeMirror( textarea );
|
|
const mwLang = mediaWikiLang(
|
|
{ bidiIsolation: true },
|
|
{ tags: {} }
|
|
);
|
|
cm.initialize( [ ...cm.defaultExtensions, mwLang ] );
|
|
|
|
describe( 'CodeMirrorBidiIsolation', () => {
|
|
it.each( testCases )(
|
|
'bidi isolation ($title)',
|
|
( { input, output } ) => {
|
|
cm.view.dispatch( {
|
|
changes: {
|
|
from: 0,
|
|
to: cm.view.state.doc.length,
|
|
insert: input
|
|
}
|
|
} );
|
|
cm.$textarea.textSelection = jest.fn().mockReturnValue( input );
|
|
expect( cm.view.dom.querySelector( '.cm-content' ).innerHTML ).toStrictEqual( output );
|
|
}
|
|
);
|
|
} );
|