mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-24 14:33:59 +00:00
Add handling for mw:DisplaySpace
It's supposed to be non-editable but deletable text, like mw:Entity. We decided to handle them this way in 2015 but never implemented it (T94509). Currently, accidentally editing text inside of mw:DisplaySpace node causes the changes to be lost when saving. Bug: T241906 Change-Id: I78a0cc7a75061a7eefb8b677898b5756326615d6
This commit is contained in:
parent
4637b224b4
commit
8341f96217
|
@ -31,16 +31,28 @@ ve.dm.MWEntityNode.static.isContent = true;
|
|||
|
||||
ve.dm.MWEntityNode.static.matchTagNames = [ 'span' ];
|
||||
|
||||
ve.dm.MWEntityNode.static.matchRdfaTypes = [ 'mw:Entity' ];
|
||||
ve.dm.MWEntityNode.static.matchRdfaTypes = [ 'mw:Entity', 'mw:DisplaySpace' ];
|
||||
|
||||
ve.dm.MWEntityNode.static.allowedRdfaTypes = [ 'mw:Placeholder' ];
|
||||
|
||||
ve.dm.MWEntityNode.static.toDataElement = function ( domElements ) {
|
||||
return { type: this.name, attributes: { character: domElements[ 0 ].textContent } };
|
||||
var dataElement = {
|
||||
type: this.name,
|
||||
attributes: {
|
||||
character: domElements[ 0 ].textContent
|
||||
}
|
||||
};
|
||||
if ( domElements[ 0 ].getAttribute( 'typeof' ).indexOf( 'mw:DisplaySpace' ) !== -1 ) {
|
||||
dataElement.attributes.displaySpace = true;
|
||||
}
|
||||
return dataElement;
|
||||
};
|
||||
|
||||
ve.dm.MWEntityNode.static.toDomElements = function ( dataElement, doc ) {
|
||||
var domElement = doc.createElement( 'span' ),
|
||||
textNode = doc.createTextNode( dataElement.attributes.character );
|
||||
domElement.setAttribute( 'typeof', 'mw:Entity' );
|
||||
domElement.setAttribute( 'typeof',
|
||||
dataElement.attributes.displaySpace ? 'mw:DisplaySpace mw:Placeholder' : 'mw:Entity' );
|
||||
domElement.appendChild( textNode );
|
||||
return [ domElement ];
|
||||
};
|
||||
|
|
|
@ -1767,6 +1767,27 @@ ve.dm.mwExample.domToDataCases = {
|
|||
{ type: '/internalList' }
|
||||
]
|
||||
},
|
||||
'mw:DisplaySpace': {
|
||||
body: '<p>a<span typeof="mw:DisplaySpace mw:Placeholder"> </span>: b</p>',
|
||||
data: [
|
||||
{ type: 'paragraph' },
|
||||
'a',
|
||||
{
|
||||
type: 'mwEntity',
|
||||
attributes: {
|
||||
character: '\u00a0',
|
||||
displaySpace: true
|
||||
}
|
||||
},
|
||||
{ type: '/mwEntity' },
|
||||
':',
|
||||
' ',
|
||||
'b',
|
||||
{ type: '/paragraph' },
|
||||
{ type: 'internalList' },
|
||||
{ type: '/internalList' }
|
||||
]
|
||||
},
|
||||
'wrapping with mw:Entity': {
|
||||
body: 'a<span typeof="mw:Entity">¢</span>b<span typeof="mw:Entity">¥</span><span typeof="mw:Entity">™</span>',
|
||||
data: [
|
||||
|
|
Loading…
Reference in a new issue