Divec has uploaded a new change for review.

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


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

Detect outdated pending post KeyPress handler

modules/ve/ce/ve.ce.Surface.js
* KeyPress handler: save id for the post-event setTimeout
* KeyDown handler: cancel the poller and poll immediately if pending.

Bug: 53079
Change-Id: If139ff3230c10caa616743f71659c4606d290310
---
M modules/ve/ce/ve.ce.Surface.js
1 file changed, 15 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/13/81213/1

diff --git a/modules/ve/ce/ve.ce.Surface.js b/modules/ve/ce/ve.ce.Surface.js
index cbc5ba1..ffa25f6 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,13 @@
  */
 ve.ce.Surface.prototype.onDocumentKeyDown = function ( e ) {
        var trigger;
+       if ( this.keyPressTimeout !== null ) {
+               // Cancel the pending poll, and do a synchronous one instead
+               clearTimeout( this.keyPressTimeout );
+               this.keyPressTimeout = null;
+               ve.log( 'keydown clash ' + document.getElementsByClassName( 
've-ce-documentNode' )[0].innerHTML.substring(0, 100) );
+               this.surfaceObserver.start( false, true );
+       }
 
        // Ignore keydowns while in IME mode but do not preventDefault them (so 
text actually appear on
        // the screen).
@@ -514,6 +522,11 @@
 ve.ce.Surface.prototype.onDocumentKeyPress = function ( e ) {
        var selection, prevNode, documentModel = this.model.getDocument();
 
+       // I *think* there's no need to check for a pending keyPressTimeout 
here, because it
+       // will have already been cancelled by the onDocumentKeyDown. This 
assumes that there's
+       // no way we can ever get two consecutive KeyPress events without an 
intervening
+       // KeyDown event. Perhaps some IME/browser combination will violate 
this :-/
+
        // Prevent IE from editing Aliens/Entities
        // TODO: Better comment about what's going on here is needed.
        if ( $.browser.msie === true ) {
@@ -539,7 +552,8 @@
        }
 
        this.handleInsertion();
-       setTimeout( ve.bind( function () {
+       this.keyPressTimeout = setTimeout( ve.bind( function () {
+               this.keyPressTimeout = null;
                this.surfaceObserver.start( false, true );
        }, this ) );
 };

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If139ff3230c10caa616743f71659c4606d290310
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Divec <[email protected]>

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

Reply via email to