Merge "Do not focus CE on mobile when editor opens"

This commit is contained in:
jenkins-bot 2014-08-22 22:50:59 +00:00 committed by Gerrit Code Review
commit 8462907ae3
2 changed files with 57 additions and 42 deletions

View file

@ -69,7 +69,6 @@ ve.init.mw.MobileViewTarget.static.name = 'mobile';
* Once surface is ready ready, init UI. * Once surface is ready ready, init UI.
*/ */
ve.init.mw.MobileViewTarget.prototype.onSurfaceReady = function () { ve.init.mw.MobileViewTarget.prototype.onSurfaceReady = function () {
this.surface.getView().focus();
this.restoreEditSection(); this.restoreEditSection();
}; };
@ -103,13 +102,22 @@ ve.init.mw.MobileViewTarget.prototype.setupToolbar = function () {
/** /**
* @inheritdoc * @inheritdoc
*/ */
ve.init.mw.MobileViewTarget.prototype.scrollToHeading = function ( headingNode ) { ve.init.mw.MobileViewTarget.prototype.goToHeading = function ( headingNode ) {
var position; this.scrollToHeading( headingNode );
};
if ( this.isIos ) {
position = headingNode.$element.offset().top - this.toolbar.$element.height(); /**
this.surface.$element.closest( '.overlay-content' ).scrollTop( position ); * @inheritdoc
} else { */
ve.init.mw.MobileViewTarget.super.prototype.scrollToHeading.call( this, headingNode ); 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 );
}
} );
}; };

View file

@ -1432,14 +1432,10 @@ ve.init.mw.Target.prototype.startSanityCheck = function () {
*/ */
ve.init.mw.Target.prototype.restoreEditSection = function () { ve.init.mw.Target.prototype.restoreEditSection = function () {
if ( this.section !== undefined && this.section > 0 ) { if ( this.section !== undefined && this.section > 0 ) {
var offset, offsetNode, nextNode, var surfaceView = this.surface.getView(),
target = this,
surfaceView = this.surface.getView(),
surfaceModel = surfaceView.getModel(),
$documentNode = surfaceView.getDocument().getDocumentNode().$element, $documentNode = surfaceView.getDocument().getDocumentNode().$element,
$section = $documentNode.find( 'h1, h2, h3, h4, h5, h6' ).eq( this.section - 1 ), $section = $documentNode.find( 'h1, h2, h3, h4, h5, h6' ).eq( this.section - 1 ),
headingNode = $section.data( 'view' ), headingNode = $section.data( 'view' );
lastHeadingLevel = -1;
if ( $section.length ) { if ( $section.length ) {
this.initialEditSummary = '/* ' + this.initialEditSummary = '/* ' +
@ -1447,32 +1443,47 @@ ve.init.mw.Target.prototype.restoreEditSection = function () {
} }
if ( headingNode ) { if ( headingNode ) {
// Find next sibling which isn't a heading this.goToHeading( headingNode );
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.section = undefined; 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. * 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 * @param {ve.ce.HeadingNode} headingNode Heading node to scroll to
*/ */
ve.init.mw.Target.prototype.scrollToHeading = function ( headingNode ) { ve.init.mw.Target.prototype.scrollToHeading = function ( headingNode ) {
var $window = $( OO.ui.Element.getWindow( this.$element ) ), var $window = $( OO.ui.Element.getWindow( this.$element ) );
target = this;
// Wait for toolbar to animate in so we can account for its height $window.scrollTop( headingNode.$element.offset().top - this.toolbar.$element.height() );
setTimeout( function () {
$window.scrollTop( headingNode.$element.offset().top - target.toolbar.$element.height() );
}, 200 );
}; };