jenkins-bot has submitted this change and it was merged.

Change subject: Detect outdated pending post KeyPress handler
......................................................................


Detect outdated pending post KeyPress handler

modules/ve/ce/ve.ce.Surface.js
* Schedule the post-keypress async handler in a way that can be cancelled.
* Cancel it and run the handler immediately if another key event happens.

Bug: 53079
Change-Id: If139ff3230c10caa616743f71659c4606d290310
---
M modules/ve/ce/ve.ce.Surface.js
1 file changed, 36 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 cbc5ba1..f4b52e6 100644
--- a/modules/ve/ce/ve.ce.Surface.js
+++ b/modules/ve/ce/ve.ce.Surface.js
@@ -33,6 +33,7 @@
        this.documentView = new ve.ce.Document( model.getDocument(), this );
        this.surfaceObserver = new ve.ce.SurfaceObserver( this.documentView );
        this.selectionTimeout = null;
+       this.keyPressTimeout = null;
        this.$document = $( this.getElementDocument() );
        this.clipboard = {};
        this.renderingEnabled = true;
@@ -450,6 +451,7 @@
  */
 ve.ce.Surface.prototype.onDocumentKeyDown = function ( e ) {
        var trigger;
+       this.forceKeyPressTimeout();
 
        // Ignore keydowns while in IME mode but do not preventDefault them (so 
text actually appear on
        // the screen).
@@ -514,6 +516,8 @@
 ve.ce.Surface.prototype.onDocumentKeyPress = function ( e ) {
        var selection, prevNode, documentModel = this.model.getDocument();
 
+       this.forceKeyPressTimeout();
+
        // Prevent IE from editing Aliens/Entities
        // TODO: Better comment about what's going on here is needed.
        if ( $.browser.msie === true ) {
@@ -539,12 +543,42 @@
        }
 
        this.handleInsertion();
-       setTimeout( ve.bind( function () {
-               this.surfaceObserver.start( false, true );
+       this.setKeyPressTimeout();
+};
+
+/**
+ * Append a call to onKeyPressTimeout to the event queue.
+ * @method
+ */
+ve.ce.Surface.prototype.setKeyPressTimeout = function () {
+       this.keyPressTimeout = setTimeout( ve.bind( function() {
+               this.keyPressTimeout = null;
+               this.onKeyPressTimeout();
        }, this ) );
 };
 
 /**
+ * If there is a pending call to onKeyPressTimeout in the event queue, delete 
it and call now
+ * @method
+ */
+ve.ce.Surface.prototype.forceKeyPressTimeout = function () {
+       if ( this.keyPressTimeout === null ) {
+               return;
+       }
+       clearTimeout( this.keyPressTimeout );
+       this.keyPressTimeout = null;
+       this.onKeyPressTimeout();
+};
+
+/**
+ * post-keypress handler: re-sync the surface and model
+ * @method
+ */
+ve.ce.Surface.prototype.onKeyPressTimeout = function () {
+       this.surfaceObserver.start( false, true );
+};
+
+/**
  * Handle document key up events.
  *
  * @method

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

Gerrit-MessageType: merged
Gerrit-Change-Id: If139ff3230c10caa616743f71659c4606d290310
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Divec <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Inez <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to