Ensure text version of counter is written to external links when copying

Bug: T137503
Change-Id: Iae791253ea272847984fee5d0586dc302027f1bd
This commit is contained in:
Ed Sanders 2016-06-27 15:19:53 +01:00
parent 4973740ae3
commit aeca19c9ea
2 changed files with 23 additions and 3 deletions

View file

@ -55,8 +55,27 @@ ve.dm.MWNumberedExternalLinkNode.static.toDataElement = function ( domElements )
}; };
}; };
ve.dm.MWNumberedExternalLinkNode.static.toDomElements = function ( dataElement, doc ) { ve.dm.MWNumberedExternalLinkNode.static.toDomElements = function ( dataElement, doc, converter ) {
var domElement = doc.createElement( 'a' ); var counter, offset,
node = this,
domElement = doc.createElement( 'a' );
// Ensure there is a text version of the counter in the clipboard
// as external documents may not have the same stylesheet - and Firefox
// discards empty tags on copy.
if ( converter.isForClipboard() ) {
counter = 1;
offset = converter.documentData.indexOf( dataElement );
if ( offset !== -1 ) {
converter.documentData.slice( 0, offset ).forEach( function ( el ) {
if ( el.type && el.type === node.name ) {
counter++;
}
} );
}
domElement.appendChild( doc.createTextNode( '[' + counter + ']' ) );
}
domElement.setAttribute( 'href', dataElement.attributes.href ); domElement.setAttribute( 'href', dataElement.attributes.href );
domElement.setAttribute( 'rel', 'mw:ExtLink' ); domElement.setAttribute( 'rel', 'mw:ExtLink' );
return [ domElement ]; return [ domElement ];

View file

@ -1106,7 +1106,8 @@ ve.dm.mwExample.domToDataCases = {
{ type: '/paragraph' }, { type: '/paragraph' },
{ type: 'internalList' }, { type: 'internalList' },
{ type: '/internalList' } { type: '/internalList' }
] ],
clipboardBody: '<p>Foo<a rel="mw:ExtLink" href="http://www.example.com">[1]</a>Bar</p>'
}, },
'URL link': { 'URL link': {
body: '<p><a rel="mw:ExtLink" href="http://www.mediawiki.org/">mw</a></p>', body: '<p><a rel="mw:ExtLink" href="http://www.mediawiki.org/">mw</a></p>',