Esanders has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/147498

Change subject: Update context menu according to stricter rules
......................................................................

Update context menu according to stricter rules

* Connect to onContextChange instead of onModelUpdate
* Never emit context changes while staging

Change-Id: Id5d1dbb367d6e4e34d70bc8dd668b08bf928e4cd
---
M modules/ve/dm/ve.dm.Surface.js
M modules/ve/ui/ve.ui.Context.js
M modules/ve/ui/ve.ui.DesktopContext.js
3 files changed, 35 insertions(+), 42 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/98/147498/1

diff --git a/modules/ve/dm/ve.dm.Surface.js b/modules/ve/dm/ve.dm.Surface.js
index d1132b2..cab6db9 100644
--- a/modules/ve/dm/ve.dm.Surface.js
+++ b/modules/ve/dm/ve.dm.Surface.js
@@ -314,7 +314,9 @@
                new ve.dm.AnnotationSet( this.documentModel.getStore() );
 
        this.emit( 'insertionAnnotationsChange', this.insertionAnnotations );
-       this.emit( 'contextChange' );
+       if ( !this.isStaging() ) {
+               this.emit( 'contextChange' );
+       }
 };
 
 /**
@@ -338,7 +340,9 @@
        }
 
        this.emit( 'insertionAnnotationsChange', this.insertionAnnotations );
-       this.emit( 'contextChange' );
+       if ( !this.isStaging() ) {
+               this.emit( 'contextChange' );
+       }
 };
 
 /**
@@ -362,7 +366,9 @@
        }
 
        this.emit( 'insertionAnnotationsChange', this.insertionAnnotations );
-       this.emit( 'contextChange' );
+       if ( !this.isStaging() ) {
+               this.emit( 'contextChange' );
+       }
 };
 
 /**
@@ -486,7 +492,7 @@
 ve.dm.Surface.prototype.emitContextChange = function () {
        if ( this.queueingContextChanges ) {
                this.contextChangeQueued = true;
-       } else {
+       } else if ( !this.isStaging() ) {
                this.emit( 'contextChange' );
        }
 };
@@ -505,7 +511,9 @@
                this.queueingContextChanges = false;
                if ( this.contextChangeQueued ) {
                        this.contextChangeQueued = false;
-                       this.emit( 'contextChange' );
+                       if ( !this.isStaging() ) {
+                               this.emit( 'contextChange' );
+                       }
                }
        }
 };
diff --git a/modules/ve/ui/ve.ui.Context.js b/modules/ve/ui/ve.ui.Context.js
index e0ba6a7..9fac7a1 100644
--- a/modules/ve/ui/ve.ui.Context.js
+++ b/modules/ve/ui/ve.ui.Context.js
@@ -26,14 +26,13 @@
        this.inspector = null;
        this.inspectors = this.createInspectorWindowManager();
        this.menu = new ve.ui.ContextMenuWidget( { '$': this.$ } );
-       this.afterModelChangeTimeout = null;
-       this.afterModelChangeRange = null;
-       this.afterModelChangeHandler = ve.bind( this.afterModelChange, this );
+       this.afterContextChangeTimeout = null;
+       this.afterContextChangeHandler = ve.bind( this.afterContextChange, this 
);
 
        // Events
        this.surface.getModel().connect( this, {
-               'documentUpdate': 'onModelChange',
-               'select': 'onModelChange'
+               'contextChange': 'onContextChange',
+               'select': 'onContextChange'
        } );
        this.inspectors.connect( this, { 'opening': 'onInspectorOpening' } );
        this.menu.connect( this, { 'choose': 'onContextItemChoose' } );
@@ -51,33 +50,27 @@
 /* Methods */
 
 /**
- * Handle model change event.
+ * Handle context change event.
  *
  * While an inspector is opening or closing, all changes are ignored so as to 
prevent inspectors
  * that change the selection from within their setup or teardown processes 
changing context state.
  *
  * The response to selection changes is deferred to prevent teardown processes 
handlers that change
  * the selection from causing this function to recurse. These responses are 
also debounced for
- * efficiency, so that if there are three selection changes in the same tick, 
#afterModelChange only
+ * efficiency, so that if there are three selection changes in the same tick, 
#afterContextChange only
  * runs once.
  *
- * @param {ve.Range} range Range if triggered by selection change, null 
otherwise
- * @see #afterModelChange
+ * @see #afterContextChange
  */
-ve.ui.Context.prototype.onModelChange = function ( range ) {
+ve.ui.Context.prototype.onContextChange = function () {
        if ( this.inspector && ( this.inspector.isOpening() || 
this.inspector.isClosing() ) ) {
                // Cancel debounced change handler
-               clearTimeout( this.afterModelChangeTimeout );
-               this.afterModelChangeTimeout = null;
-               this.afterModelChangeRange = null;
+               clearTimeout( this.afterContextChangeTimeout );
+               this.afterContextChangeTimeout = null;
        } else {
-               if ( this.afterModelChangeTimeout === null ) {
+               if ( this.afterContextChangeTimeout === null ) {
                        // Ensure change is handled on next cycle
-                       this.afterModelChangeTimeout = setTimeout( 
this.afterModelChangeHandler );
-               }
-               if ( range instanceof ve.Range ) {
-                       // Store the latest range
-                       this.afterModelChangeRange = range;
+                       this.afterContextChangeTimeout = setTimeout( 
this.afterContextChangeHandler );
                }
        }
        // Purge available tools cache
@@ -85,24 +78,15 @@
 };
 
 /**
- * Handle debounced model change events.
+ * Handle debounced context change events.
  */
-ve.ui.Context.prototype.afterModelChange = function () {
+ve.ui.Context.prototype.afterContextChange = function () {
        // Reset debouncing state
-       this.afterModelChangeTimeout = null;
-       this.afterModelChangeRange = null;
+       this.afterContextChangeTimeout = null;
 
-       this.onContextChange();
-};
-
-/**
- * Handle context change events.
- */
-ve.ui.Context.prototype.onContextChange = function () {
-       var inspectable = this.isInspectable();
        if ( this.isVisible() ) {
                if ( this.menu.isVisible() ) {
-                       if ( inspectable ) {
+                       if ( this.isInspectable() ) {
                                // Change state: menu -> menu
                                this.populateMenu();
                                this.updateDimensions();
@@ -116,7 +100,7 @@
                        this.inspector.close();
                }
        } else {
-               if ( inspectable ) {
+               if ( this.isInspectable() ) {
                        // Change state: closed -> menu
                        this.menu.toggle( true );
                        this.populateMenu();
@@ -321,7 +305,7 @@
        this.menu.disconnect( this );
 
        // Stop timers
-       clearTimeout( this.afterModelChangeTimeout );
+       clearTimeout( this.afterContextChangeTimeout );
 
        this.$element.remove();
        this.inspectors.$element.remove();
diff --git a/modules/ve/ui/ve.ui.DesktopContext.js 
b/modules/ve/ui/ve.ui.DesktopContext.js
index 37bd286..8e1fc22 100644
--- a/modules/ve/ui/ve.ui.DesktopContext.js
+++ b/modules/ve/ui/ve.ui.DesktopContext.js
@@ -57,13 +57,14 @@
 /**
  * @inheritdoc
  */
-ve.ui.DesktopContext.prototype.onContextChange = function () {
+ve.ui.DesktopContext.prototype.afterContextChange = function () {
+       // Parent method
+       ve.ui.DesktopContext.super.prototype.afterContextChange.call( this );
+
        // Bypass while dragging
        if ( this.suppressed ) {
                return;
        }
-       // Parent method
-       ve.ui.DesktopContext.super.prototype.onContextChange.call( this );
 };
 
 /**

-- 
To view, visit https://gerrit.wikimedia.org/r/147498
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id5d1dbb367d6e4e34d70bc8dd668b08bf928e4cd
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <esand...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to