mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 10:35:48 +00:00
Place cursor at start of paragraph, not heading, when section-editing
Also checks for subheadings, i.e. we keep moving forward one sibling as long as the next sibling is a heading of higher order than the previous one. If the heading is of the same or lower order then we assume there is an empty section, so we just stop. Bug: 49563 Change-Id: I6fcc463aeeae40278f5caf04ae251c8ecfe65472
This commit is contained in:
parent
1889495aa2
commit
138b9365c2
|
@ -1881,13 +1881,26 @@ ve.init.mw.ViewPageTarget.prototype.restoreEditSection = function () {
|
|||
surfaceView = this.surface.getView(),
|
||||
surfaceModel = surfaceView.getModel();
|
||||
this.$document.find( 'h1, h2, h3, h4, h5, h6' ).eq( this.section - 1 ).each( function () {
|
||||
var headingNode = $( this ).data( 'view' );
|
||||
var offsetNode, nextNode,
|
||||
headingNode = $( this ).data( 'view' ),
|
||||
lastHeadingLevel = -1;
|
||||
|
||||
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(
|
||||
headingNode.getModel().getOffset()
|
||||
offsetNode.getModel().getOffset(), 1
|
||||
);
|
||||
surfaceModel.change( null, new ve.Range( offset, offset ) );
|
||||
surfaceModel.change( null, new ve.Range( offset ) );
|
||||
// Scroll to heading:
|
||||
// Wait for toolbar to animate in so we can account for its height
|
||||
setTimeout( function () {
|
||||
|
|
Loading…
Reference in a new issue