mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-24 22:35:41 +00:00
Fix bug with nested lists in getCoveredSiblingGroups()
For nested lists, this function would return multiple groups where one was wholly contained in the other, use offsets to prevent that from happening. Change-Id: Ib03bb1c81712d805cc263c2975cc3942de63d2ed
This commit is contained in:
parent
d31b562dc7
commit
ce0371e8ae
|
@ -371,6 +371,14 @@ ve.Document.prototype.selectNodes = function( range, mode ) {
|
|||
return retval;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return groups of sibling nodes covered by the given range
|
||||
* @param {ve.Range} selection Range
|
||||
* @return {Array} Array of objects. Each object has the following keys:
|
||||
* nodes: Array of sibling nodes covered by a part of range
|
||||
* parent: Parent of all of these nodes
|
||||
* grandparent: parent's parent
|
||||
*/
|
||||
ve.Document.prototype.getCoveredSiblingGroups = function( selection ) {
|
||||
var leaves = this.selectNodes( selection, 'leaves' ),
|
||||
firstCoveredSibling,
|
||||
|
@ -378,10 +386,13 @@ ve.Document.prototype.getCoveredSiblingGroups = function( selection ) {
|
|||
node,
|
||||
parentNode,
|
||||
siblingNode,
|
||||
groups = [];
|
||||
// Iterate through covered leaf nodes and process either a conversion or wrapping for groups of
|
||||
// consecutive covered siblings - for conversion, the entire list will be changed
|
||||
groups = [],
|
||||
lastEndOffset = 0;
|
||||
for ( var i = 0; i < leaves.length; i++ ) {
|
||||
if ( leaves[i].nodeOuterRange.end <= lastEndOffset ) {
|
||||
// This range is contained within a range we've already processed
|
||||
continue;
|
||||
}
|
||||
node = leaves[i].node;
|
||||
// Traverse up to a content branch from content elements
|
||||
if ( node.isContent() ) {
|
||||
|
@ -411,6 +422,7 @@ ve.Document.prototype.getCoveredSiblingGroups = function( selection ) {
|
|||
siblingNode = siblingNode.getParent();
|
||||
}
|
||||
} while ( siblingNode.getParent() === parentNode );
|
||||
lastEndOffset = parentNode.getOuterRange().end;
|
||||
}
|
||||
return groups;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue