mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 10:35:48 +00:00
Cancel VE when escape key pressed
Or at least open the confirmation dialog about it. Relies on I0047bd9d to not break stuff on the second try. Bug: T52868 Change-Id: Id178a2a0aad2f4bf5f589d66efde61aaa6fae498
This commit is contained in:
parent
268a852455
commit
c0fd5e616d
2
lib/ve
2
lib/ve
|
@ -1 +1 @@
|
|||
Subproject commit c8201dddc99334481ef939606753c283dc69c3ed
|
||||
Subproject commit eed8fcb877f6b6cd0181e453bb2633c83dc9927b
|
|
@ -122,7 +122,7 @@ ve.init.mw.ViewPageTarget = function VeInitMwViewPageTarget() {
|
|||
|
||||
this.setupSkinTabs();
|
||||
|
||||
window.addEventListener( 'popstate', this.onWindowPopState.bind( this ) ) ;
|
||||
window.addEventListener( 'popstate', this.onWindowPopState.bind( this ) );
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
@ -257,6 +257,9 @@ ve.init.mw.ViewPageTarget.prototype.activate = function () {
|
|||
this.originalEditondbclick = mw.user.options.get( 'editondblclick' );
|
||||
mw.user.options.set( 'editondblclick', 0 );
|
||||
|
||||
this.onDocumentKeyDownHandler = this.onDocumentKeyDown.bind( this );
|
||||
$( document ).on( 'keydown', this.onDocumentKeyDownHandler );
|
||||
|
||||
// User interface changes
|
||||
this.transformPage();
|
||||
this.hideReadOnlyContent();
|
||||
|
@ -287,7 +290,7 @@ ve.init.mw.ViewPageTarget.prototype.deactivate = function ( override, trackMecha
|
|||
this.surface.dialogs.openWindow( 'cancelconfirm' ).then( function ( opened ) {
|
||||
opened.then( function ( closing ) {
|
||||
closing.then( function ( data ) {
|
||||
if ( data.action === 'discard' ) {
|
||||
if ( data && data.action === 'discard' ) {
|
||||
target.cancel( trackMechanism );
|
||||
}
|
||||
} );
|
||||
|
@ -332,6 +335,8 @@ ve.init.mw.ViewPageTarget.prototype.cancel = function ( trackMechanism ) {
|
|||
this.restorePage();
|
||||
this.showReadOnlyContent();
|
||||
|
||||
$( document ).off( 'keydown', this.onDocumentKeyDownHandler );
|
||||
|
||||
mw.user.options.set( 'editondblclick', this.originalEditondbclick );
|
||||
this.originalEditondbclick = undefined;
|
||||
|
||||
|
@ -456,6 +461,20 @@ ve.init.mw.ViewPageTarget.prototype.onSurfaceReady = function () {
|
|||
mw.hook( 've.activationComplete' ).fire();
|
||||
};
|
||||
|
||||
ve.init.mw.ViewPageTarget.prototype.onDocumentKeyDown = function ( e ) {
|
||||
if ( e.which === OO.ui.Keys.ESCAPE ) {
|
||||
if ( this.active ) {
|
||||
this.deactivate( false, 'navigate-read' );
|
||||
e.preventDefault();
|
||||
} else if ( this.activating ) {
|
||||
this.deactivate( true, 'navigate-read' );
|
||||
this.activating = false;
|
||||
e.preventDefault();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle successful DOM save event.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue