Divec has uploaded a new change for review.
https://gerrit.wikimedia.org/r/267292
Change subject: WIP: Fix node and offset calculations
......................................................................
WIP: Fix node and offset calculations
Bug: T124318
Change-Id: Ifac0131aa3b33bff03b80f6b3433e241c85ca1a8
---
M src/ce/ve.ce.Document.js
1 file changed, 19 insertions(+), 11 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor
refs/changes/92/267292/1
diff --git a/src/ce/ve.ce.Document.js b/src/ce/ve.ce.Document.js
index d9f5f27..0e011b7 100644
--- a/src/ce/ve.ce.Document.js
+++ b/src/ce/ve.ce.Document.js
@@ -180,7 +180,7 @@
// - is between an empty unicorn pair: return inter-unicorn location
// At the desired offset:
// - If is a text node: return that node and the correct remainder
offset
- // - Else return the first maximally deep element at the offset
+ // - Else return a maximally deep element at the offset (the first such
in document order)
// Otherwise, signal an error
// Unfortunately, there is no way to avoid slugless block nodes with no
DM length: an
@@ -203,16 +203,21 @@
stack = [ current ];
while ( stack.length > 0 ) {
if ( current.offset >= current.$contents.length ) {
- stack.pop();
- current = stack[ stack.length - 1 ];
if ( current && startOffset === offset ) {
- // The current node has no DOM children and no
DM length (e.g.
- // it is a browser-generated <br/> that doesn't
have class
- // ve-ce-leafNode), but the node itself is at
the required DM
- // offset. Return the first offset inside this
node (even if
- // it's a node type that cannot contain
content, like br).
+ // The current node has no DM length (e.g. it
is a browser
+ // generated <br/> that doesn't have class
ve-ce-leafNode), and
+ // we have passed all its DOM children. But the
node itself is
+ // at the required DM offset. Return the first
offset inside
+ // this node (even if it's a node type that
cannot contain
+ // content, like br).
+ // In fact, we can deduce that the node has no
DOM children:
+ // otherwise it would have had a DOM child with
no DM length at
+ // the required DM offset, so we would have
already have
+ // returned.
return { node: current.$contents[
current.offset - 1 ], offset: 0 };
}
+ stack.pop();
+ current = stack[ stack.length - 1 ];
continue;
}
item = current.$contents[ current.offset ];
@@ -277,10 +282,13 @@
continue;
} else {
// Any other node type (e.g. b, inline slug,
browser-generated br
- // that doesn't have class ve-ce-leafNode):
descend
- stack.push( { $contents: $item.contents(),
offset: 0 } );
+ // that doesn't have class ve-ce-leafNode)
current.offset++;
- current = stack[ stack.length - 1 ];
+ if ( $item.contents().length > 0 ) {
+ // There are some contents: descend
+ stack.push( { $contents:
$item.contents(), offset: 0 } );
+ current = stack[ stack.length - 1 ];
+ }
continue;
}
}
--
To view, visit https://gerrit.wikimedia.org/r/267292
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifac0131aa3b33bff03b80f6b3433e241c85ca1a8
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Divec <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits