jenkins-bot has submitted this change and it was merged.
Change subject: Don't bounce selection changes DM->CE
......................................................................
Don't bounce selection changes DM->CE
ve.ce.Surface.js
* changeModelSelection: store selection temporarily for bounce detection
* onChange: do nothing if bounce is detected
Change-Id: I758e7a72a5690463f12f456419c6e471dd29a9db
---
M modules/ve/ce/ve.ce.Surface.js
1 file changed, 28 insertions(+), 2 deletions(-)
Approvals:
Catrope: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/ve/ce/ve.ce.Surface.js b/modules/ve/ce/ve.ce.Surface.js
index c3d4d68..119a298 100644
--- a/modules/ve/ce/ve.ce.Surface.js
+++ b/modules/ve/ce/ve.ce.Surface.js
@@ -51,6 +51,9 @@
this.pasting = false;
this.clickHistory = [];
this.focusedNode = null;
+ // This is set on entering changeModelSelection, then unset when
leaving.
+ // It is used to test whether a reflected change event is emitted.
+ this.newModelSelection = null;
// Events
this.surfaceObserver.connect(
@@ -913,7 +916,9 @@
next = null,
previous = this.focusedNode;
- if ( selection ) {
+ // Ignore selection if changeModelSelection is currently being called
with the same
+ // (object-identical) selection object (i.e. if the model is calling us
back)
+ if ( selection && selection !== this.newModelSelection ) {
// Detect when only a single inline element is selected
if ( !selection.isCollapsed() ) {
start =
this.documentView.getDocumentNode().getNodeFromOffset( selection.start + 1 );
@@ -975,7 +980,7 @@
}
this.incRenderLock();
try {
- this.model.change( null, newRange );
+ this.changeModelSelection( newRange );
} finally {
this.decRenderLock();
}
@@ -1849,3 +1854,24 @@
ve.ce.Surface.prototype.getDir = function () {
return this.$.css( 'direction' );
};
+
+/**
+ * Change selection in the model only, not the CE surface
+ *
+ * This avoids event storms when the CE surface is already correct
+ *
+ * @method
+ * @param {ve.Range} range New selection for model
+ * @throws {Error} If calls to the method are nested
+ */
+ve.ce.Surface.prototype.changeModelSelection = function ( range ) {
+ if ( this.newModelSelection !== null ) {
+ throw new Error( 'Nested changeModelSelection' );
+ }
+ this.newModelSelection = range;
+ try {
+ this.model.change( null, range );
+ } finally {
+ this.newModelSelection = null;
+ }
+};
--
To view, visit https://gerrit.wikimedia.org/r/86688
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I758e7a72a5690463f12f456419c6e471dd29a9db
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Divec <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Divec <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits