Index: trunk/parsers/wikidom/lib/es/es.ListBlock.js |
— | — | @@ -43,22 +43,32 @@ |
44 | 44 | position.left += lineOffset.left - blockOffset.left;
|
45 | 45 | position.bottom += lineOffset.top - blockOffset.top;
|
46 | 46 |
|
| 47 | + this.traverseItems( function( item ) {
|
| 48 | + if ( item === location.item ) {
|
| 49 | + return false;
|
| 50 | + }
|
| 51 | + position.line += item.flow.lines.length;
|
| 52 | + } );
|
| 53 | + return position;
|
| 54 | +};
|
| 55 | +
|
| 56 | +es.ListBlock.prototype.traverseItems = function( callback ) {
|
47 | 57 | // Recursively walk the tree of list items and their lists, depth first, until we get to the
|
48 | 58 | // same item as location.item, incrementing position.line for each line that occurs before it
|
49 | 59 | var stack = [{ 'list': this.list, 'index': 0 }],
|
50 | 60 | list,
|
51 | 61 | item,
|
52 | 62 | pop,
|
53 | | - parent;
|
| 63 | + parent,
|
| 64 | + index = 0;
|
54 | 65 | while ( stack.length ) {
|
55 | 66 | iteration = stack[stack.length - 1];
|
56 | 67 | pop = true;
|
57 | 68 | while ( iteration.index < iteration.list.items.length ) {
|
58 | 69 | item = iteration.list.items[iteration.index++];
|
59 | | - if ( item === location.item ) {
|
60 | | - return position;
|
| 70 | + if ( callback( item, index++ ) === false ) {
|
| 71 | + return false;
|
61 | 72 | }
|
62 | | - position.line += item.flow.lines.length;
|
63 | 73 | if ( item.lists.length ) {
|
64 | 74 | parent = stack.length;
|
65 | 75 | for ( var i = 0; i < item.lists.length; i++ ) {
|
— | — | @@ -76,7 +86,7 @@ |
77 | 87 | }
|
78 | 88 | }
|
79 | 89 | }
|
80 | | - return position;
|
| 90 | + return true;
|
81 | 91 | };
|
82 | 92 |
|
83 | 93 | es.ListBlock.prototype.getOffset = function( position ) {
|