mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 02:23:58 +00:00
Merge "Do not focus CE on mobile when editor opens"
This commit is contained in:
commit
8462907ae3
|
@ -69,7 +69,6 @@ ve.init.mw.MobileViewTarget.static.name = 'mobile';
|
|||
* Once surface is ready ready, init UI.
|
||||
*/
|
||||
ve.init.mw.MobileViewTarget.prototype.onSurfaceReady = function () {
|
||||
this.surface.getView().focus();
|
||||
this.restoreEditSection();
|
||||
};
|
||||
|
||||
|
@ -103,13 +102,22 @@ ve.init.mw.MobileViewTarget.prototype.setupToolbar = function () {
|
|||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.init.mw.MobileViewTarget.prototype.scrollToHeading = function ( headingNode ) {
|
||||
var position;
|
||||
|
||||
if ( this.isIos ) {
|
||||
position = headingNode.$element.offset().top - this.toolbar.$element.height();
|
||||
this.surface.$element.closest( '.overlay-content' ).scrollTop( position );
|
||||
} else {
|
||||
ve.init.mw.MobileViewTarget.super.prototype.scrollToHeading.call( this, headingNode );
|
||||
}
|
||||
ve.init.mw.MobileViewTarget.prototype.goToHeading = function ( headingNode ) {
|
||||
this.scrollToHeading( headingNode );
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.init.mw.MobileViewTarget.prototype.scrollToHeading = function ( headingNode ) {
|
||||
var target = this, position;
|
||||
|
||||
setTimeout( function () {
|
||||
if ( target.isIos ) {
|
||||
position = headingNode.$element.offset().top - target.toolbar.$element.height();
|
||||
target.surface.$element.closest( '.overlay-content' ).scrollTop( position );
|
||||
} else {
|
||||
ve.init.mw.MobileViewTarget.super.prototype.scrollToHeading.call( target, headingNode );
|
||||
}
|
||||
} );
|
||||
};
|
||||
|
|
|
@ -1432,14 +1432,10 @@ ve.init.mw.Target.prototype.startSanityCheck = function () {
|
|||
*/
|
||||
ve.init.mw.Target.prototype.restoreEditSection = function () {
|
||||
if ( this.section !== undefined && this.section > 0 ) {
|
||||
var offset, offsetNode, nextNode,
|
||||
target = this,
|
||||
surfaceView = this.surface.getView(),
|
||||
surfaceModel = surfaceView.getModel(),
|
||||
var surfaceView = this.surface.getView(),
|
||||
$documentNode = surfaceView.getDocument().getDocumentNode().$element,
|
||||
$section = $documentNode.find( 'h1, h2, h3, h4, h5, h6' ).eq( this.section - 1 ),
|
||||
headingNode = $section.data( 'view' ),
|
||||
lastHeadingLevel = -1;
|
||||
headingNode = $section.data( 'view' );
|
||||
|
||||
if ( $section.length ) {
|
||||
this.initialEditSummary = '/* ' +
|
||||
|
@ -1447,32 +1443,47 @@ ve.init.mw.Target.prototype.restoreEditSection = function () {
|
|||
}
|
||||
|
||||
if ( headingNode ) {
|
||||
// Find next sibling which isn't a heading
|
||||
offsetNode = headingNode;
|
||||
while ( offsetNode instanceof ve.ce.HeadingNode && offsetNode.getModel().getAttribute( 'level' ) > lastHeadingLevel ) {
|
||||
lastHeadingLevel = offsetNode.getModel().getAttribute( 'level' );
|
||||
// Next sibling
|
||||
nextNode = offsetNode.parent.children[ve.indexOf( offsetNode, offsetNode.parent.children ) + 1];
|
||||
if ( !nextNode ) {
|
||||
break;
|
||||
}
|
||||
offsetNode = nextNode;
|
||||
}
|
||||
offset = surfaceModel.getDocument().data.getNearestContentOffset(
|
||||
offsetNode.getModel().getOffset(), 1
|
||||
);
|
||||
// onDocumentFocus is debounced, so wait for that to happen before setting
|
||||
// the model selection, otherwise it will get reset
|
||||
this.surface.getView().once( 'focus', function () {
|
||||
surfaceModel.setSelection( new ve.Range( offset ) );
|
||||
target.scrollToHeading( headingNode );
|
||||
} );
|
||||
this.goToHeading( headingNode );
|
||||
}
|
||||
|
||||
this.section = undefined;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Move the cursor to a given heading and scroll to it.
|
||||
*
|
||||
* @method
|
||||
* @param {ve.ce.HeadingNode} headingNode Heading node to scroll to
|
||||
*/
|
||||
ve.init.mw.Target.prototype.goToHeading = function ( headingNode ) {
|
||||
var nextNode, offset,
|
||||
target = this,
|
||||
offsetNode = headingNode,
|
||||
surfaceModel = this.surface.getView().getModel(),
|
||||
lastHeadingLevel = -1;
|
||||
|
||||
// Find next sibling which isn't a heading
|
||||
while ( offsetNode instanceof ve.ce.HeadingNode && offsetNode.getModel().getAttribute( 'level' ) > lastHeadingLevel ) {
|
||||
lastHeadingLevel = offsetNode.getModel().getAttribute( 'level' );
|
||||
// Next sibling
|
||||
nextNode = offsetNode.parent.children[ve.indexOf( offsetNode, offsetNode.parent.children ) + 1];
|
||||
if ( !nextNode ) {
|
||||
break;
|
||||
}
|
||||
offsetNode = nextNode;
|
||||
}
|
||||
offset = surfaceModel.getDocument().data.getNearestContentOffset(
|
||||
offsetNode.getModel().getOffset(), 1
|
||||
);
|
||||
// onDocumentFocus is debounced, so wait for that to happen before setting
|
||||
// the model selection, otherwise it will get reset
|
||||
this.surface.getView().once( 'focus', function () {
|
||||
surfaceModel.setSelection( new ve.Range( offset ) );
|
||||
target.scrollToHeading( headingNode );
|
||||
} );
|
||||
};
|
||||
|
||||
/**
|
||||
* Scroll to a given heading in the document.
|
||||
*
|
||||
|
@ -1480,11 +1491,7 @@ ve.init.mw.Target.prototype.restoreEditSection = function () {
|
|||
* @param {ve.ce.HeadingNode} headingNode Heading node to scroll to
|
||||
*/
|
||||
ve.init.mw.Target.prototype.scrollToHeading = function ( headingNode ) {
|
||||
var $window = $( OO.ui.Element.getWindow( this.$element ) ),
|
||||
target = this;
|
||||
var $window = $( OO.ui.Element.getWindow( this.$element ) );
|
||||
|
||||
// Wait for toolbar to animate in so we can account for its height
|
||||
setTimeout( function () {
|
||||
$window.scrollTop( headingNode.$element.offset().top - target.toolbar.$element.height() );
|
||||
}, 200 );
|
||||
$window.scrollTop( headingNode.$element.offset().top - this.toolbar.$element.height() );
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue