Esanders has uploaded a new change for review. https://gerrit.wikimedia.org/r/171852
Change subject: Remove and restore selection for non-isolated dialogs ...................................................................... Remove and restore selection for non-isolated dialogs In non-isolated mode the only way to prevent accidental typing in the document is by removing the native selection, so do this. This unavoidably sets the model selection to null, so when the dialog closes, restore the selection if it hasn't been already by an action. Bug: 73097 Change-Id: I93f741734ff3d46397c1278c500ae3c124a3a14f --- M src/ui/actions/ve.ui.WindowAction.js M src/ui/ve.ui.Surface.js 2 files changed, 19 insertions(+), 24 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor refs/changes/52/171852/1 diff --git a/src/ui/actions/ve.ui.WindowAction.js b/src/ui/actions/ve.ui.WindowAction.js index 8eb3124..c41e3fe 100644 --- a/src/ui/actions/ve.ui.WindowAction.js +++ b/src/ui/actions/ve.ui.WindowAction.js @@ -45,19 +45,32 @@ ve.ui.WindowAction.prototype.open = function ( name, data ) { var windowManager, windowClass = ve.ui.windowFactory.lookup( name ), - fragment = this.surface.getModel().getFragment( undefined, true ), - dir = this.surface.getView().getDocument().getDirectionFromSelection( fragment.getSelection() ) || - this.surface.getModel().getDocument().getDir(); + surface = this.surface, + fragment = surface.getModel().getFragment( undefined, true ), + dir = surface.getView().getDocument().getDirectionFromSelection( fragment.getSelection() ) || + surface.getModel().getDocument().getDir(); data = ve.extendObject( { dir: dir }, data, { fragment: fragment } ); if ( windowClass ) { if ( windowClass.prototype instanceof ve.ui.FragmentInspector ) { - windowManager = this.surface.getContext().getInspectors(); + windowManager = surface.getContext().getInspectors(); + windowManager.openWindow( name, data ); } else if ( windowClass.prototype instanceof OO.ui.Dialog ) { - windowManager = this.surface.getDialogs(); + // For non-isolated dialogs, remove the selection and re-apply on close + surface.getView().nativeSelection.removeAllRanges(); + windowManager = surface.getDialogs(); + windowManager.openWindow( name, data ).then( function ( opened ) { + opened.then( function ( closing ) { + closing.then( function () { + // Check the dialog didn't modify the selection before restoring from fragment + if ( surface.getModel().getSelection().isNull() ) { + fragment.select(); + } + } ); + } ); + } ); } - windowManager.openWindow( name, data ); } }; diff --git a/src/ui/ve.ui.Surface.js b/src/ui/ve.ui.Surface.js index 5abfd23..e52c614 100644 --- a/src/ui/ve.ui.Surface.js +++ b/src/ui/ve.ui.Surface.js @@ -50,9 +50,6 @@ this.context = this.createContext(); this.filibuster = null; - // Events - this.dialogs.connect( this, { closing: 'onDialogClosing' } ); - // Initialization this.$menus.append( this.context.$element ); this.$element @@ -118,21 +115,6 @@ // Let others know we have been destroyed this.emit( 'destroy' ); -}; - -/** - * Handle dialog teardown events - */ -ve.ui.Surface.prototype.onDialogClosing = function ( win, closing ) { - var surface = this; - closing.progress( function ( data ) { - if ( data.state === 'teardown' ) { - // Return focus to view - surface.getView().focus(); - // Re-assert selection - surface.getModel().getFragment().select(); - } - } ); }; /** -- To view, visit https://gerrit.wikimedia.org/r/171852 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I93f741734ff3d46397c1278c500ae3c124a3a14f 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