mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-29 00:30:44 +00:00
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
This commit is contained in:
parent
3f7761d242
commit
d867ef8fc0
|
@ -33,6 +33,7 @@ ve.ce.Surface = function VeCeSurface( model, surface, options ) {
|
||||||
this.documentView = new ve.ce.Document( model.getDocument(), this );
|
this.documentView = new ve.ce.Document( model.getDocument(), this );
|
||||||
this.surfaceObserver = new ve.ce.SurfaceObserver( this.documentView );
|
this.surfaceObserver = new ve.ce.SurfaceObserver( this.documentView );
|
||||||
this.selectionTimeout = null;
|
this.selectionTimeout = null;
|
||||||
|
this.keyPressTimeout = null;
|
||||||
this.$document = $( this.getElementDocument() );
|
this.$document = $( this.getElementDocument() );
|
||||||
this.clipboard = {};
|
this.clipboard = {};
|
||||||
this.renderingEnabled = true;
|
this.renderingEnabled = true;
|
||||||
|
@ -450,6 +451,7 @@ ve.ce.Surface.prototype.onDocumentDrop = function ( e ) {
|
||||||
*/
|
*/
|
||||||
ve.ce.Surface.prototype.onDocumentKeyDown = function ( e ) {
|
ve.ce.Surface.prototype.onDocumentKeyDown = function ( e ) {
|
||||||
var trigger;
|
var trigger;
|
||||||
|
this.forceKeyPressTimeout();
|
||||||
|
|
||||||
// Ignore keydowns while in IME mode but do not preventDefault them (so text actually appear on
|
// Ignore keydowns while in IME mode but do not preventDefault them (so text actually appear on
|
||||||
// the screen).
|
// the screen).
|
||||||
|
@ -514,6 +516,8 @@ ve.ce.Surface.prototype.onDocumentKeyDown = function ( e ) {
|
||||||
ve.ce.Surface.prototype.onDocumentKeyPress = function ( e ) {
|
ve.ce.Surface.prototype.onDocumentKeyPress = function ( e ) {
|
||||||
var selection, prevNode, documentModel = this.model.getDocument();
|
var selection, prevNode, documentModel = this.model.getDocument();
|
||||||
|
|
||||||
|
this.forceKeyPressTimeout();
|
||||||
|
|
||||||
// Prevent IE from editing Aliens/Entities
|
// Prevent IE from editing Aliens/Entities
|
||||||
// TODO: Better comment about what's going on here is needed.
|
// TODO: Better comment about what's going on here is needed.
|
||||||
if ( $.browser.msie === true ) {
|
if ( $.browser.msie === true ) {
|
||||||
|
@ -539,11 +543,41 @@ ve.ce.Surface.prototype.onDocumentKeyPress = function ( e ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.handleInsertion();
|
this.handleInsertion();
|
||||||
setTimeout( ve.bind( function () {
|
this.setKeyPressTimeout();
|
||||||
this.surfaceObserver.start( false, true );
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 ) );
|
}, 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.
|
* Handle document key up events.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue