jenkins-bot has submitted this change and it was merged.
Change subject: MWLinkNodeInspector: Actually preserve annotations when
converting to link annotation
......................................................................
MWLinkNodeInspector: Actually preserve annotations when converting to link
annotation
This was implemented, but didn't work because the node was removed
before its annotations were copied.
Also fixed:
* Don't do an unnecessary transaction to change attributes of a node
we're going to remove anyway.
* Apply the same link href fixups when converting as when not
(previously, changing the href to 'example.com' and clicking "Add
label" would break the link in interesting ways).
* Do a single transaction from replacement instead of removal+insertion
when possible.
Bug: 67377
Change-Id: I0318ae62c799300fb7696506a9736b839e2c8578
---
M modules/ve-mw/ui/inspectors/ve.ui.MWLinkNodeInspector.js
1 file changed, 17 insertions(+), 19 deletions(-)
Approvals:
Catrope: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/ve-mw/ui/inspectors/ve.ui.MWLinkNodeInspector.js
b/modules/ve-mw/ui/inspectors/ve.ui.MWLinkNodeInspector.js
index e474614..bc231be 100644
--- a/modules/ve-mw/ui/inspectors/ve.ui.MWLinkNodeInspector.js
+++ b/modules/ve-mw/ui/inspectors/ve.ui.MWLinkNodeInspector.js
@@ -106,40 +106,38 @@
nodeRange = this.selectedNode.getOuterRange(),
value = this.targetInput.getValue(),
convert = data.action === 'convert',
- remove = convert || data.action === 'remove' ||
!value;
+ remove = data.action === 'remove' || !value;
+
+ // Default to http:// if the external link doesn't
already begin with a supported
+ // protocol - this prevents the link from being
converted into literal text upon
+ // save and also fixes a common mistake users may make
+ if (
!ve.init.platform.getExternalLinkUrlProtocolsRegExp().test( value ) ) {
+ value = 'http://' + value;
+ }
if ( remove ) {
surfaceModel.change(
ve.dm.Transaction.newFromRemoval( doc,
nodeRange )
);
- } else {
- // Default to http:// if the external link
doesn't already begin with a supported
- // protocol - this prevents the link from being
converted into literal text upon
- // save and also fixes a common mistake users
may make
- if (
!ve.init.platform.getExternalLinkUrlProtocolsRegExp().test( value ) ) {
- value = 'http://' + value;
- }
- surfaceModel.change(
-
ve.dm.Transaction.newFromAttributeChanges(
- doc, nodeRange.start, { 'href':
value }
- )
- );
- }
- if ( convert ) {
+ } else if ( convert ) {
annotation = new
ve.dm.MWExternalLinkAnnotation( {
'type': 'link/mwExternal',
'attributes': {
'href': value
}
} );
- annotations = doc.data.getAnnotationsFromOffset(
- this.selectedNode.getOffset()
- ).clone();
+ annotations =
doc.data.getAnnotationsFromOffset( nodeRange.start ).clone();
annotations.push( annotation );
content = ve.splitClusters( value );
ve.dm.Document.static.addAnnotationsToData(
content, annotations );
surfaceModel.change(
- ve.dm.Transaction.newFromInsertion(
doc, nodeRange.start, content )
+ ve.dm.Transaction.newFromReplacement(
doc, nodeRange, content )
+ );
+ } else {
+ surfaceModel.change(
+
ve.dm.Transaction.newFromAttributeChanges(
+ doc, nodeRange.start, { 'href':
value }
+ )
);
}
}, this );
--
To view, visit https://gerrit.wikimedia.org/r/143387
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0318ae62c799300fb7696506a9736b839e2c8578
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Trevor Parscal <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits