2012-07-19 00:11:26 +00:00
|
|
|
/**
|
|
|
|
* VisualEditor example data sets and helper functions.
|
2012-07-19 21:25:16 +00:00
|
|
|
*
|
2012-07-19 00:11:26 +00:00
|
|
|
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2012-05-10 04:11:09 +00:00
|
|
|
/* Static Members */
|
|
|
|
|
|
|
|
ve.example = {};
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.example.getSelectNodesCases = function ( doc ) {
|
2012-05-10 04:11:09 +00:00
|
|
|
var lookup = ve.example.lookupNode,
|
|
|
|
documentNode = doc.getDocumentNode();
|
|
|
|
return [
|
2012-10-04 22:24:02 +00:00
|
|
|
{
|
|
|
|
'actual': doc.selectNodes( new ve.Range( 1 ), 'branches' ),
|
|
|
|
'expected': [
|
|
|
|
// heading
|
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 0 ),
|
|
|
|
'range': new ve.Range( 1 ),
|
|
|
|
'index': 0,
|
|
|
|
'nodeRange': new ve.Range( 1, 4 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 0, 5 )
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'actual': doc.selectNodes( new ve.Range( 10 ), 'branches' ),
|
|
|
|
'expected': [
|
2012-10-19 20:56:46 +00:00
|
|
|
// table/tableSection/tableRow/tableCell/paragraph
|
2012-10-04 22:24:02 +00:00
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 1, 0, 0, 0, 0 ),
|
|
|
|
'range': new ve.Range( 10 ),
|
|
|
|
'index': 0,
|
|
|
|
'nodeRange': new ve.Range( 10, 11 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 9, 12 )
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'actual': doc.selectNodes( new ve.Range( 20 ), 'branches' ),
|
|
|
|
'expected': [
|
2012-10-19 20:56:46 +00:00
|
|
|
// table/tableSection/tableRow/tableCell/list/listItem/list/listItem/paragraph
|
2012-10-04 22:24:02 +00:00
|
|
|
{
|
2012-10-19 20:56:46 +00:00
|
|
|
'node': lookup( documentNode, 1, 0, 0, 0, 1, 0, 1, 0, 0 ),
|
2012-10-04 22:24:02 +00:00
|
|
|
'range': new ve.Range( 20 ),
|
|
|
|
'index': 0,
|
|
|
|
'nodeRange': new ve.Range( 20, 21 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 19, 22 )
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'actual': doc.selectNodes( new ve.Range( 1, 20 ), 'branches' ),
|
|
|
|
'expected': [
|
|
|
|
// heading
|
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 0 ),
|
|
|
|
'range': new ve.Range( 1, 4 ),
|
|
|
|
'index': 0,
|
|
|
|
'nodeRange': new ve.Range( 1, 4 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 0, 5 )
|
|
|
|
},
|
|
|
|
|
2012-10-19 20:56:46 +00:00
|
|
|
// table/tableSection/tableRow/tableCell/paragraph
|
2012-10-04 22:24:02 +00:00
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 1, 0, 0, 0, 0 ),
|
|
|
|
'index': 0,
|
|
|
|
'nodeRange': new ve.Range( 10, 11 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 9, 12 )
|
|
|
|
},
|
|
|
|
|
2012-10-19 20:56:46 +00:00
|
|
|
// table/tableSection/tableRow/tableCell/list/listItem/paragraph
|
2012-10-04 22:24:02 +00:00
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 1, 0, 0, 0, 1, 0, 0 ),
|
|
|
|
'index': 0,
|
|
|
|
'nodeRange': new ve.Range( 15, 16 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 14, 17 )
|
|
|
|
},
|
|
|
|
|
2012-10-19 20:56:46 +00:00
|
|
|
// table/tableSection/tableRow/tableCell/list/listItem/list/listItem/paragraph
|
2012-10-04 22:24:02 +00:00
|
|
|
{
|
2012-10-19 20:56:46 +00:00
|
|
|
'node': lookup( documentNode, 1, 0, 0, 0, 1, 0, 1, 0, 0 ),
|
2012-10-04 22:24:02 +00:00
|
|
|
'range': new ve.Range( 20 ),
|
|
|
|
'index': 0,
|
|
|
|
'nodeRange': new ve.Range( 20, 21 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 19, 22 )
|
2012-10-19 20:56:46 +00:00
|
|
|
}
|
2012-10-04 22:24:02 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'actual': doc.selectNodes( new ve.Range( 1 ), 'branches' ),
|
|
|
|
'expected': [
|
|
|
|
// heading
|
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 0 ),
|
|
|
|
'range': new ve.Range( 1 ),
|
|
|
|
'index': 0,
|
|
|
|
'nodeRange': new ve.Range( 1, 4 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 0, 5 )
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2012-05-10 04:11:09 +00:00
|
|
|
{
|
|
|
|
'actual': doc.selectNodes( new ve.Range( 0, 3 ), 'leaves' ),
|
|
|
|
'expected': [
|
2012-05-15 05:54:53 +00:00
|
|
|
// heading/text
|
2012-05-10 22:03:23 +00:00
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 0, 0 ),
|
|
|
|
'range': new ve.Range( 1, 3 ),
|
|
|
|
'index': 0,
|
2012-06-04 23:18:29 +00:00
|
|
|
'nodeRange': new ve.Range( 1, 4 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 1, 4 )
|
2012-05-10 22:03:23 +00:00
|
|
|
}
|
2012-05-15 05:54:53 +00:00
|
|
|
],
|
2012-05-15 07:25:27 +00:00
|
|
|
'msg': 'partial leaf results have ranges with global offsets'
|
2012-05-10 04:11:09 +00:00
|
|
|
},
|
|
|
|
{
|
2012-06-08 05:08:49 +00:00
|
|
|
'actual': doc.selectNodes( new ve.Range( 0, 11 ), 'leaves' ),
|
2012-05-10 04:11:09 +00:00
|
|
|
'expected': [
|
2012-05-15 05:54:53 +00:00
|
|
|
// heading/text
|
2012-05-10 22:03:23 +00:00
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 0, 0 ),
|
|
|
|
'index': 0,
|
2012-06-04 23:18:29 +00:00
|
|
|
'nodeRange': new ve.Range( 1, 4 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 1, 4 )
|
2012-05-10 22:03:23 +00:00
|
|
|
},
|
2012-06-08 05:08:49 +00:00
|
|
|
// table/tableSection/tableRow/tableCell/paragraph/text
|
2012-05-10 22:03:23 +00:00
|
|
|
{
|
2012-06-08 05:08:49 +00:00
|
|
|
'node': lookup( documentNode, 1, 0, 0, 0, 0, 0 ),
|
2012-05-10 22:03:23 +00:00
|
|
|
'index': 0,
|
2012-06-08 05:08:49 +00:00
|
|
|
'nodeRange': new ve.Range( 10, 11 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 10, 11 )
|
2012-05-10 22:03:23 +00:00
|
|
|
}
|
2012-05-15 05:54:53 +00:00
|
|
|
],
|
|
|
|
'msg': 'leaf nodes do not have ranges, leaf nodes from different levels'
|
2012-05-10 04:11:09 +00:00
|
|
|
},
|
|
|
|
{
|
2012-06-08 05:08:49 +00:00
|
|
|
'actual': doc.selectNodes( new ve.Range( 29, 43 ), 'leaves' ),
|
2012-05-10 04:11:09 +00:00
|
|
|
'expected': [
|
2012-06-08 05:08:49 +00:00
|
|
|
// table/tableSection/tableRow/tableCell/list/listItem/paragraph/text
|
2012-05-10 22:03:23 +00:00
|
|
|
{
|
2012-06-08 05:08:49 +00:00
|
|
|
'node': lookup( documentNode, 1, 0, 0, 0, 2, 0, 0, 0 ),
|
2012-05-10 22:03:23 +00:00
|
|
|
'index': 0,
|
2012-06-08 05:08:49 +00:00
|
|
|
'nodeRange': new ve.Range( 29, 30 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 29, 30 )
|
2012-05-10 22:03:23 +00:00
|
|
|
},
|
2012-05-10 04:11:09 +00:00
|
|
|
// preformatted/text
|
2012-05-10 22:03:23 +00:00
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 2, 0 ),
|
|
|
|
'index': 0,
|
2012-06-08 05:08:49 +00:00
|
|
|
'nodeRange': new ve.Range( 38, 39 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 38, 39 )
|
2012-05-10 22:03:23 +00:00
|
|
|
},
|
2012-05-15 05:54:53 +00:00
|
|
|
// preformatted/image
|
2012-05-10 22:03:23 +00:00
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 2, 1 ),
|
|
|
|
'index': 1,
|
2012-06-08 05:08:49 +00:00
|
|
|
'nodeRange': new ve.Range( 40, 40 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 39, 41 )
|
2012-05-10 22:03:23 +00:00
|
|
|
},
|
2012-05-10 04:11:09 +00:00
|
|
|
// preformatted/text
|
2012-05-10 22:03:23 +00:00
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 2, 2 ),
|
|
|
|
'index': 2,
|
2012-06-08 05:08:49 +00:00
|
|
|
'nodeRange': new ve.Range( 41, 42 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 41, 42 )
|
2012-05-10 22:03:23 +00:00
|
|
|
}
|
2012-05-15 05:54:53 +00:00
|
|
|
],
|
|
|
|
'msg': 'leaf nodes that are not text nodes'
|
2012-05-10 04:11:09 +00:00
|
|
|
},
|
|
|
|
{
|
2012-06-08 05:08:49 +00:00
|
|
|
'actual': doc.selectNodes( new ve.Range( 2, 16 ), 'siblings' ),
|
2012-05-10 04:11:09 +00:00
|
|
|
'expected': [
|
|
|
|
// heading
|
2012-05-10 22:03:23 +00:00
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 0 ),
|
|
|
|
'range': new ve.Range( 2, 4 ),
|
|
|
|
'index': 0,
|
2012-06-04 23:18:29 +00:00
|
|
|
'nodeRange': new ve.Range( 1, 4 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 0, 5 )
|
2012-05-10 22:03:23 +00:00
|
|
|
},
|
2012-05-10 04:11:09 +00:00
|
|
|
// table
|
2012-05-10 22:03:23 +00:00
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 1 ),
|
2012-06-08 05:08:49 +00:00
|
|
|
'range': new ve.Range( 6, 16 ),
|
2012-05-10 22:03:23 +00:00
|
|
|
'index': 1,
|
2012-06-08 05:08:49 +00:00
|
|
|
'nodeRange': new ve.Range( 6, 36 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 5, 37 )
|
2012-05-10 22:03:23 +00:00
|
|
|
}
|
2012-05-15 05:54:53 +00:00
|
|
|
],
|
|
|
|
'msg': 'siblings at the document level'
|
2012-05-10 04:11:09 +00:00
|
|
|
},
|
|
|
|
{
|
2012-06-08 05:08:49 +00:00
|
|
|
'actual': doc.selectNodes( new ve.Range( 2, 51 ), 'siblings' ),
|
2012-05-10 04:11:09 +00:00
|
|
|
'expected': [
|
|
|
|
// heading
|
2012-05-10 22:03:23 +00:00
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 0 ),
|
|
|
|
'range': new ve.Range( 2, 4 ),
|
|
|
|
'index': 0,
|
2012-06-04 23:18:29 +00:00
|
|
|
'nodeRange': new ve.Range( 1, 4 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 0, 5 )
|
2012-05-10 22:03:23 +00:00
|
|
|
},
|
2012-05-10 04:11:09 +00:00
|
|
|
// table
|
2012-05-10 22:03:23 +00:00
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 1 ),
|
|
|
|
'index': 1,
|
2012-06-08 05:08:49 +00:00
|
|
|
'nodeRange': new ve.Range( 6, 36 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 5, 37 )
|
2012-05-10 22:03:23 +00:00
|
|
|
},
|
2012-05-10 04:11:09 +00:00
|
|
|
// preformatted
|
2012-05-10 22:03:23 +00:00
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 2 ),
|
|
|
|
'index': 2,
|
2012-06-08 05:08:49 +00:00
|
|
|
'nodeRange': new ve.Range( 38, 42 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 37, 43 )
|
2012-05-10 22:03:23 +00:00
|
|
|
},
|
2012-05-10 04:11:09 +00:00
|
|
|
// definitionList
|
2012-05-10 22:03:23 +00:00
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 3 ),
|
2012-06-08 05:08:49 +00:00
|
|
|
'range': new ve.Range( 44, 51 ),
|
2012-05-10 22:03:23 +00:00
|
|
|
'index': 3,
|
2012-06-08 05:08:49 +00:00
|
|
|
'nodeRange': new ve.Range( 44, 54 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 43, 55 )
|
2012-05-10 22:03:23 +00:00
|
|
|
}
|
2012-05-15 05:54:53 +00:00
|
|
|
],
|
|
|
|
'msg': 'more than 2 siblings at the document level'
|
2012-05-10 23:08:15 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'actual': doc.selectNodes( new ve.Range( 1, 1 ), 'leaves' ),
|
|
|
|
'expected': [
|
|
|
|
// heading/text
|
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 0, 0 ),
|
|
|
|
'range': new ve.Range( 1, 1 ),
|
|
|
|
'index': 0,
|
2012-06-04 23:18:29 +00:00
|
|
|
'nodeRange': new ve.Range( 1, 4 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 1, 4 )
|
2012-05-10 23:08:15 +00:00
|
|
|
}
|
2012-05-15 05:54:53 +00:00
|
|
|
],
|
|
|
|
'msg': 'zero-length range at the start of a text node returns text node rather than parent'
|
2012-05-10 23:42:16 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'actual': doc.selectNodes( new ve.Range( 4, 4 ), 'leaves' ),
|
|
|
|
'expected': [
|
|
|
|
// heading/text
|
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 0, 0 ),
|
|
|
|
'range': new ve.Range( 4, 4 ),
|
|
|
|
'index': 0,
|
2012-06-04 23:18:29 +00:00
|
|
|
'nodeRange': new ve.Range( 1, 4 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 1, 4 )
|
2012-05-10 23:42:16 +00:00
|
|
|
}
|
2012-05-15 05:54:53 +00:00
|
|
|
],
|
|
|
|
'msg': 'zero-length range at the end of a text node returns text node rather than parent'
|
2012-05-10 23:42:16 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'actual': doc.selectNodes( new ve.Range( 2, 3 ), 'leaves' ),
|
|
|
|
'expected': [
|
|
|
|
// heading/text
|
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 0, 0 ),
|
|
|
|
'range': new ve.Range( 2, 3 ),
|
|
|
|
'index': 0,
|
2012-06-04 23:18:29 +00:00
|
|
|
'nodeRange': new ve.Range( 1, 4 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 1, 4 )
|
2012-05-10 23:42:16 +00:00
|
|
|
}
|
2012-05-15 05:54:53 +00:00
|
|
|
],
|
|
|
|
'msg': 'range entirely within one leaf node'
|
2012-05-11 03:08:12 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'actual': doc.selectNodes( new ve.Range( 5, 5 ), 'leaves' ),
|
|
|
|
'expected': [
|
|
|
|
// document
|
|
|
|
{
|
|
|
|
'node': documentNode,
|
|
|
|
'range': new ve.Range( 5, 5 ),
|
|
|
|
// no 'index' because documentNode has no parent
|
|
|
|
'indexInNode': 1,
|
2012-06-08 05:08:49 +00:00
|
|
|
'nodeRange': new ve.Range( 0, 61 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 0, 61 )
|
2012-05-11 03:08:12 +00:00
|
|
|
}
|
2012-05-15 05:54:53 +00:00
|
|
|
],
|
|
|
|
'msg': 'zero-length range between two children of the document'
|
2012-05-15 01:44:19 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'actual': doc.selectNodes( new ve.Range( 0, 0 ), 'leaves' ),
|
|
|
|
'expected': [
|
|
|
|
// document
|
|
|
|
{
|
|
|
|
'node': documentNode,
|
|
|
|
'range': new ve.Range( 0, 0 ),
|
|
|
|
// no 'index' because documentNode has no parent
|
|
|
|
'indexInNode': 0,
|
2012-06-08 05:08:49 +00:00
|
|
|
'nodeRange': new ve.Range( 0, 61 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 0, 61 )
|
2012-05-15 01:44:19 +00:00
|
|
|
}
|
2012-05-15 05:54:53 +00:00
|
|
|
],
|
|
|
|
'msg': 'zero-length range at the start of the document'
|
2012-06-05 13:49:30 +00:00
|
|
|
},
|
|
|
|
{
|
2012-06-08 05:08:49 +00:00
|
|
|
'actual': doc.selectNodes( new ve.Range( 32, 39 ), 'leaves' ),
|
2012-06-05 13:49:30 +00:00
|
|
|
'expected': [
|
2012-07-07 18:13:31 +00:00
|
|
|
// table/tableSection/tableRow/tableCell/list
|
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 1, 0, 0, 0, 2 ),
|
|
|
|
'range': new ve.Range( 32, 32 ),
|
|
|
|
'index': 2,
|
|
|
|
'indexInNode': 1,
|
|
|
|
'nodeRange': new ve.Range( 27, 32 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 26, 33 )
|
|
|
|
},
|
2012-06-05 13:49:30 +00:00
|
|
|
// preformatted/text
|
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 2, 0 ),
|
|
|
|
// no 'range' because the text node is covered completely
|
|
|
|
'index': 0,
|
2012-06-08 05:08:49 +00:00
|
|
|
'nodeRange': new ve.Range( 38, 39 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 38, 39 )
|
2012-06-05 13:49:30 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
'msg': 'range with 5 closings and a text node'
|
2012-06-06 18:30:16 +00:00
|
|
|
},
|
|
|
|
{
|
2012-06-08 05:08:49 +00:00
|
|
|
'actual': doc.selectNodes( new ve.Range( 2, 57 ), 'covered' ),
|
2012-06-06 18:30:16 +00:00
|
|
|
'expected': [
|
|
|
|
// heading/text
|
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 0, 0 ),
|
|
|
|
'range': new ve.Range( 2, 4 ),
|
|
|
|
'index': 0,
|
|
|
|
'nodeRange': new ve.Range( 1, 4 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 1, 4 )
|
|
|
|
},
|
|
|
|
// table
|
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 1 ),
|
|
|
|
// no 'range' because the table is covered completely
|
|
|
|
'index': 1,
|
2012-06-08 05:08:49 +00:00
|
|
|
'nodeRange': new ve.Range( 6, 36 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 5, 37 )
|
2012-06-06 18:30:16 +00:00
|
|
|
},
|
|
|
|
// preformatted
|
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 2 ),
|
|
|
|
// no 'range' because the node is covered completely
|
|
|
|
'index': 2,
|
2012-06-08 05:08:49 +00:00
|
|
|
'nodeRange': new ve.Range( 38, 42 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 37, 43 )
|
2012-06-06 18:30:16 +00:00
|
|
|
},
|
|
|
|
// definitionList
|
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 3 ),
|
|
|
|
// no 'range' because the node is covered completely
|
|
|
|
'index': 3,
|
2012-06-08 05:08:49 +00:00
|
|
|
'nodeRange': new ve.Range( 44, 54 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 43, 55 )
|
2012-06-06 18:30:16 +00:00
|
|
|
},
|
|
|
|
// paragraph/text
|
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 4, 0 ),
|
|
|
|
// no 'range' because the text node is covered completely
|
|
|
|
'index': 0,
|
2012-06-08 05:08:49 +00:00
|
|
|
'nodeRange': new ve.Range( 56, 57 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 56, 57 )
|
2012-06-06 18:30:16 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
'msg': 'range from the first heading into the second-to-last paragraph, in covered mode'
|
2012-06-20 00:12:36 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'actual': doc.selectNodes( new ve.Range( 14, 14 ), 'siblings' ),
|
|
|
|
'expected': [
|
|
|
|
// table/tableSection/tableRow/tableCell/list/listItem
|
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 1, 0, 0, 0, 1, 0 ),
|
|
|
|
'range': new ve.Range( 14, 14 ),
|
|
|
|
'index': 0,
|
|
|
|
'indexInNode': 0,
|
|
|
|
'nodeRange': new ve.Range( 14, 24 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 13, 25 )
|
|
|
|
}
|
2012-07-07 18:13:31 +00:00
|
|
|
],
|
2012-06-20 00:12:36 +00:00
|
|
|
'msg': 'zero-length range at the beginning of a listItem, in siblings mode'
|
2012-07-07 18:13:31 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'actual': doc.selectNodes( new ve.Range( 25, 27 ), 'covered' ),
|
|
|
|
'expected': [
|
|
|
|
// table/tableSection/tableRow/tableCell/list
|
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 1, 0, 0, 0, 1 ),
|
|
|
|
'range': new ve.Range( 25, 25 ),
|
|
|
|
'index': 1,
|
|
|
|
'indexInNode': 1,
|
|
|
|
'nodeRange': new ve.Range( 13, 25 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 12, 26 )
|
|
|
|
},
|
|
|
|
// table/tableSection/tableRow/tableCell/list
|
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 1, 0, 0, 0, 2 ),
|
|
|
|
'range': new ve.Range( 27, 27 ),
|
|
|
|
'index': 2,
|
|
|
|
'indexInNode': 0,
|
|
|
|
'nodeRange': new ve.Range( 27, 32 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 26, 33 )
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'msg': 'range covering a list closing and a list opening'
|
2012-10-17 23:09:49 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'actual': doc.selectNodes( new ve.Range( 39, 39 ), 'leaves' ),
|
|
|
|
'expected': [
|
|
|
|
// preformatted/text
|
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 2, 0 ),
|
|
|
|
'range': new ve.Range( 39, 39 ),
|
|
|
|
'index': 0,
|
|
|
|
'nodeRange': new ve.Range( 38, 39 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 38, 39 )
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'msg': 'zero-length range in text node before inline node'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'actual': doc.selectNodes( new ve.Range( 41, 41 ), 'leaves' ),
|
|
|
|
'expected': [
|
|
|
|
// preformatted/text
|
|
|
|
{
|
|
|
|
'node': lookup( documentNode, 2, 2 ),
|
|
|
|
'range': new ve.Range( 41, 41 ),
|
|
|
|
'index': 2,
|
|
|
|
'nodeRange': new ve.Range( 41, 42 ),
|
|
|
|
'nodeOuterRange': new ve.Range( 41, 42 )
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'msg': 'zero-length range in text node after inline node'
|
2012-05-10 04:11:09 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Looks up a value in a node tree.
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-05-10 04:11:09 +00:00
|
|
|
* @method
|
|
|
|
* @param {ve.Node} root Root node to lookup from
|
Object management: Object create/inherit/clone utilities
* For the most common case:
- replace ve.extendClass with ve.inheritClass (chose slightly
different names to detect usage of the old/new one, and I
like 'inherit' better).
- move it up to below the constructor, see doc block for why.
* Cases where more than 2 arguments were passed to
ve.extendClass are handled differently depending on the case.
In case of a longer inheritance tree, the other arguments
could be omitted (like in "ve.ce.FooBar, ve.FooBar,
ve.Bar". ve.ce.FooBar only needs to inherit from ve.FooBar,
because ve.ce.FooBar inherits from ve.Bar).
In the case of where it previously had two mixins with
ve.extendClass(), either one becomes inheritClass and one
a mixin, both to mixinClass().
No visible changes should come from this commit as the
instances still all have the same visible properties in the
end. No more or less than before.
* Misc.:
- Be consistent in calling parent constructors in the
same order as the inheritance.
- Add missing @extends and @param documentation.
- Replace invalid {Integer} type hint with {Number}.
- Consistent doc comments order:
@class, @abstract, @constructor, @extends, @params.
- Fix indentation errors
A fairly common mistake was a superfluous space before the
identifier on the assignment line directly below the
documentation comment.
$ ack "^ [^*]" --js modules/ve
- Typo "Inhertiance" -> "Inheritance".
- Replacing the other confusing comment "Inheritance" (inside
the constructor) with "Parent constructor".
- Add missing @abstract for ve.ui.Tool.
- Corrected ve.FormatDropdownTool to ve.ui.FormatDropdownTool.js
- Add function names to all @constructor functions. Now that we
have inheritance it is important and useful to have these
functions not be anonymous.
Example of debug shot: http://cl.ly/image/1j3c160w3D45
Makes the difference between
< documentNode;
> ve_dm_DocumentNode
...
: ve_dm_BranchNode
...
: ve_dm_Node
...
: ve_dm_Node
...
: Object
...
without names (current situation):
< documentNode;
> Object
...
: Object
...
: Object
...
: Object
...
: Object
...
though before this commit, it really looks like this
(flattened since ve.extendClass really did a mixin):
< documentNode;
> Object
...
...
...
Pattern in Sublime (case-sensitive) to find nameless
constructor functions:
"^ve\..*\.([A-Z])([^\.]+) = function \("
Change-Id: Iab763954fb8cf375900d7a9a92dec1c755d5407e
2012-09-05 06:07:47 +00:00
|
|
|
* @param {Number} [...] Index path
|
2012-05-10 04:11:09 +00:00
|
|
|
* @param {ve.Node} Node at given path
|
|
|
|
*/
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.example.lookupNode = function ( root ) {
|
2012-07-19 03:40:49 +00:00
|
|
|
var i,
|
|
|
|
node = root;
|
|
|
|
for ( i = 1; i < arguments.length; i++ ) {
|
2012-05-10 04:11:09 +00:00
|
|
|
node = node.children[arguments[i]];
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
};
|
2012-06-07 22:02:25 +00:00
|
|
|
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.example.createDomElement = function ( type, attributes ) {
|
2012-07-19 03:40:49 +00:00
|
|
|
var key,
|
|
|
|
element = document.createElement( type );
|
|
|
|
for ( key in attributes ) {
|
2012-06-07 22:02:25 +00:00
|
|
|
element.setAttribute( key, attributes[key] );
|
|
|
|
}
|
|
|
|
return element;
|
|
|
|
};
|