mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 10:35:48 +00:00
Close inspectors when surface is focused but selection doesn't change
It's possible for the user to put the cursor back from the inspector in the surface without triggering a selection change, if the selection was collapsed and they clicked in exactly the right spot. In practice, this can happen if the link inspector is open in creation mode and the user clicks to drop the cursor at the same position where it was when the inspector was opened. When this happens, the inspector wouldn't close, because it only closed in response to selection changes. If the user then typed something, weird things would happen. To prevent this state (cursor is in surface but inspector is open) from occurring, close the inspector and hide the context when the document is focused. This fixes the link inspector creation mode issue, and it also causes the link inspector to no longer briefly remain visible after the user has clicked out of it. Bug: 56976 Change-Id: Ib70fc13031873009a175e4b049a07694a87ce25d
This commit is contained in:
parent
c06316eb64
commit
da4995888b
|
@ -54,7 +54,8 @@ ve.ui.Context = function VeUiContext( surface, config ) {
|
|||
'selectionStart': 'onSelectionStart',
|
||||
'selectionEnd': 'onSelectionEnd',
|
||||
'relocationStart': 'onRelocationStart',
|
||||
'relocationEnd': 'onRelocationEnd'
|
||||
'relocationEnd': 'onRelocationEnd',
|
||||
'focus': 'onSurfaceFocus'
|
||||
} );
|
||||
this.inspectors.connect( this, {
|
||||
'opening': 'onInspectorOpening',
|
||||
|
@ -119,6 +120,27 @@ ve.ui.Context.prototype.afterModelSelect = function () {
|
|||
this.update();
|
||||
};
|
||||
|
||||
/**
|
||||
* Respond to focus events on the surfaceView by hiding the context.
|
||||
*
|
||||
* If there's an inspector open and the user manages to drop the cursor in the surface such that
|
||||
* the selection doesn't change (i.e. the resulting model selection is equal to the previous model
|
||||
* selection), then #onModelSelect won't cause the inspector to be closed, so we do that here.
|
||||
*
|
||||
* Hiding the context immediately on focus also avoids flickering phenomena where the inspector
|
||||
* remains open or the context remains visible in the wrong place while the selection is visually
|
||||
* already moving somewhere else. We deliberately don't call #update to avoid drawing the context
|
||||
* in a place that the selection is about to move away from.
|
||||
*
|
||||
* We don't have to defer the response to this event because there is no danger that inspectors'
|
||||
* close handlers will end up invoking this handler again.
|
||||
*/
|
||||
ve.ui.Context.prototype.onSurfaceFocus = function () {
|
||||
if ( this.popup.isVisible() ) {
|
||||
this.hide();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle selection start events on the view.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue