mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeMirror
synced 2024-11-27 15:40:00 +00:00
CodeMirrorBidiIsolation: fix for when the tag is the first element
This fixes a careless error introduced in I1338afeefa where we don't do a strict equality test and thus if the tag is the first element (at position 0), the following bracket is also treated as the start position. Here we simply do a strict equality test against null (the reset value), and viola, several issues are fixed. Bug: T358804 Change-Id: I86021d363ecc33a7551bc887439dc1902914026f
This commit is contained in:
parent
ffef86bb36
commit
e1f397f048
2
resources/dist/codemirror.mode.mediawiki.js
vendored
2
resources/dist/codemirror.mode.mediawiki.js
vendored
File diff suppressed because one or more lines are too long
|
@ -29,7 +29,7 @@ function computeIsolates( view ) {
|
|||
const set = new RangeSetBuilder();
|
||||
|
||||
for ( const { from, to } of view.visibleRanges ) {
|
||||
let startPos;
|
||||
let startPos = null;
|
||||
syntaxTree( view.state ).iterate( {
|
||||
from,
|
||||
to,
|
||||
|
@ -41,7 +41,7 @@ function computeIsolates( view ) {
|
|||
mwModeConfig.tags.extTagBracket
|
||||
].includes( tag ) );
|
||||
|
||||
if ( !startPos && isBracket ) {
|
||||
if ( startPos === null && isBracket ) {
|
||||
// If we find a bracket node, we keep track of the start position.
|
||||
startPos = node.from;
|
||||
} else if ( isBracket ) {
|
||||
|
|
|
@ -6,6 +6,11 @@ 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>'
|
||||
},
|
||||
{
|
||||
title: 'wraps self-closing extension tags with span.cm-bidi-isolate',
|
||||
input: '<ref name="foo" />',
|
||||
output: '<div class="cm-line"><span class="cm-bidi-isolate"><span class="cm-mw-exttag-bracket cm-mw-ext-ref"><</span><span class="cm-mw-exttag-name cm-mw-ext-ref">ref </span><span class="cm-mw-exttag-attribute cm-mw-ext-ref">name="foo" </span><span class="cm-mw-exttag-bracket cm-mw-ext-ref">/></span></span></div>'
|
||||
}
|
||||
];
|
||||
|
||||
|
@ -16,7 +21,7 @@ document.body.appendChild( textarea );
|
|||
const cm = new CodeMirror( textarea );
|
||||
const mwLang = mediaWikiLang(
|
||||
{ bidiIsolation: true },
|
||||
{ tags: {} }
|
||||
{ tags: { ref: true } }
|
||||
);
|
||||
cm.initialize( [ ...cm.defaultExtensions, mwLang ] );
|
||||
|
||||
|
|
Loading…
Reference in a new issue