jenkins-bot has submitted this change and it was merged.
Change subject: Don't select pasted content
......................................................................
Don't select pasted content
In the process, adjust the API for SurfaceFragment#insertHtml and
SurfaceFragment#insertDocument to be consistent with
SurfaceFragment#insertContent, which leaves the selection covering
the inserted content.
Bug: T109852
Change-Id: I5a53189128dc032c02e47d1ae6e0ac2b42800b78
---
M src/ce/ve.ce.Surface.js
M src/dm/ve.dm.SurfaceFragment.js
2 files changed, 22 insertions(+), 4 deletions(-)
Approvals:
Esanders: Looks good to me, approved
jenkins-bot: Verified
diff --git a/src/ce/ve.ce.Surface.js b/src/ce/ve.ce.Surface.js
index d50a275..3f24e53 100644
--- a/src/ce/ve.ce.Surface.js
+++ b/src/ce/ve.ce.Surface.js
@@ -2222,11 +2222,15 @@
targetFragment = targetFragment || this.getModel().getFragment();
function insert( docOrData ) {
+ var resultFragment = targetFragment.collapseToEnd();
if ( docOrData instanceof ve.dm.Document ) {
- targetFragment.collapseToEnd().insertDocument(
docOrData );
+ resultFragment.insertDocument( docOrData );
} else {
- targetFragment.collapseToEnd().insertContent( docOrData
);
+ resultFragment.insertContent( docOrData );
}
+ // The resultFragment's selection now covers the inserted
content;
+ // adjust selection to end of inserted content.
+ resultFragment.collapseToEnd().select();
}
for ( i = 0, l = items.length; i < l; i++ ) {
diff --git a/src/dm/ve.dm.SurfaceFragment.js b/src/dm/ve.dm.SurfaceFragment.js
index 21d1112..4d32000 100644
--- a/src/dm/ve.dm.SurfaceFragment.js
+++ b/src/dm/ve.dm.SurfaceFragment.js
@@ -778,6 +778,10 @@
/**
* Insert HTML in the fragment.
*
+ * This will move the fragment's range to cover the inserted content. Note
that this may be
+ * different from what a normal range translation would do: the insertion
might occur
+ * at a different offset if that is needed to make the document balanced.
+ *
* @method
* @param {string} html HTML to insert
* @param {Object} [importRules] The import rules for the target surface, if
importing
@@ -791,11 +795,17 @@
/**
* Insert a ve.dm.Document in the fragment.
*
+ * This will move the fragment's range to cover the inserted content. Note
that this may be
+ * different from what a normal range translation would do: the insertion
might occur
+ * at a different offset if that is needed to make the document balanced.
+ *
* @method
* @param {ve.dm.Document} doc Document to insert
* @chainable
*/
ve.dm.SurfaceFragment.prototype.insertDocument = function ( doc ) {
+ var tx, newRange;
+
if ( !( this.selection instanceof ve.dm.LinearSelection ) ) {
return this;
}
@@ -804,11 +814,15 @@
this.removeContent();
}
- this.change( new ve.dm.Transaction.newFromDocumentInsertion(
+ tx = new ve.dm.Transaction.newFromDocumentInsertion(
this.getDocument(),
this.getSelection().getRange().start,
doc
- ) );
+ );
+ // Set the range to cover the inserted content; the offset translation
will be wrong
+ // if newFromInsertion() decided to move the insertion point
+ newRange = tx.getModifiedRange();
+ this.change( tx, new ve.dm.LinearSelection( this.getDocument(),
newRange ) );
return this;
};
--
To view, visit https://gerrit.wikimedia.org/r/233048
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I5a53189128dc032c02e47d1ae6e0ac2b42800b78
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Cscott <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits