From 14190c2b26d717e5c822c6b0bafd8127e9adc734 Mon Sep 17 00:00:00 2001 From: Philip Peitsch Date: Wed, 13 Aug 2014 17:35:58 +1000 Subject: [PATCH 1/3] Add test showing position stability issue near annotations --- webodf/tests/ops/OdtDocumentTests.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/webodf/tests/ops/OdtDocumentTests.js b/webodf/tests/ops/OdtDocumentTests.js index 4f6f4a37d..5182b2189 100644 --- a/webodf/tests/ops/OdtDocumentTests.js +++ b/webodf/tests/ops/OdtDocumentTests.js @@ -624,6 +624,8 @@ ops.OdtDocumentTests = function OdtDocumentTests(runner) { '|a|b|||c|d|1|2|', '|a||b||c|1|2|', '|a||b||1|2|', + '|||', + '|||', // *************** Annotations with highlighting *************** // From 1586b9f36cd27d7a8cc900ee0dfab66074a20150 Mon Sep 17 00:00:00 2001 From: Philip Peitsch Date: Tue, 19 Aug 2014 19:41:43 +1000 Subject: [PATCH 2/3] Add additional tests showing position stability problems --- webodf/tests/ops/operationtests.xml | 38 +++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/webodf/tests/ops/operationtests.xml b/webodf/tests/ops/operationtests.xml index 8cb328a4f..fd44a92da 100644 --- a/webodf/tests/ops/operationtests.xml +++ b/webodf/tests/ops/operationtests.xml @@ -2119,4 +2119,42 @@ ABC D E + + + ABC + + + + + + + + + + + AAlice2013-08-05T12:34:07.061ZBC + + + + + ABCD + + + + + + + + + + + + + + + + + AAlice2013-08-05T12:34:07.061Z1Alice2013-08-05T12:34:07.061ZD + + From 9fba50ac6998ebce802c97020dfb339c429c5a80 Mon Sep 17 00:00:00 2001 From: Philip Peitsch Date: Fri, 19 Sep 2014 00:36:35 +1000 Subject: [PATCH 3/3] Fix position instability around highlighted annotations By checking only nodes that pass the supplied node filter, the position logic can safely ignore out-of-place cursors near highlighted annotations. Note, this can't re-use PositionIterator.previousNode, because the logic requires the previous sibling of the current container's previous sibling. --- webodf/lib/ops/TextPositionFilter.js | 24 ++++++++++++++++++------ webodf/tests/ops/operationtests.xml | 2 +- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/webodf/lib/ops/TextPositionFilter.js b/webodf/lib/ops/TextPositionFilter.js index 670857559..04a643509 100644 --- a/webodf/lib/ops/TextPositionFilter.js +++ b/webodf/lib/ops/TextPositionFilter.js @@ -36,13 +36,27 @@ ops.TextPositionFilter = function TextPositionFilter() { /**@const*/FILTER_ACCEPT = core.PositionFilter.FilterResult.FILTER_ACCEPT, /**@const*/FILTER_REJECT = core.PositionFilter.FilterResult.FILTER_REJECT; + /** + * Find the previous sibling of the specified node that passes the node filter. + * @param {?Node} node + * @param {!function(?Node):!number} nodeFilter + * @return {?Node} + */ + function previousSibling(node, nodeFilter) { + while (node && nodeFilter(node) !== FILTER_ACCEPT) { + node = node.previousSibling; + } + return node; + } + /** * @param {!Node} container * @param {?Node} leftNode * @param {?Node} rightNode + * @param {!function(?Node):!number} nodeFilter * @return {!core.PositionFilter.FilterResult} */ - function checkLeftRight(container, leftNode, rightNode) { + function checkLeftRight(container, leftNode, rightNode, nodeFilter) { var r, firstPos, rightOfChar; // accept if there is a character immediately to the left if (leftNode) { @@ -62,9 +76,7 @@ ops.TextPositionFilter = function TextPositionFilter() { return FILTER_ACCEPT; } } else { - // Note, cant use OdfUtils.previousNode here as that function automatically dives to the previous - // elements first child (if it has one) - if (odfUtils.isInlineRoot(container.previousSibling) && odfUtils.isGroupingElement(container)) { + if (odfUtils.isGroupingElement(container) && odfUtils.isInlineRoot(previousSibling(container.previousSibling, nodeFilter))) { // Move first position after inline root inside trailing grouping element (part 2) // Allow the first position inside the first grouping element trailing an annotation return FILTER_ACCEPT; @@ -167,13 +179,13 @@ ops.TextPositionFilter = function TextPositionFilter() { leftNode = iterator.leftNode(); rightNode = container; container = /**@type{!Node}*/(container.parentNode); - r = checkLeftRight(container, leftNode, rightNode); + r = checkLeftRight(container, leftNode, rightNode, iterator.getNodeFilter()); } else if (!odfUtils.isGroupingElement(container)) { r = FILTER_REJECT; } else { leftNode = iterator.leftNode(); rightNode = iterator.rightNode(); - r = checkLeftRight(container, leftNode, rightNode); + r = checkLeftRight(container, leftNode, rightNode, iterator.getNodeFilter()); } return r; }; diff --git a/webodf/tests/ops/operationtests.xml b/webodf/tests/ops/operationtests.xml index fd44a92da..bbe901e4b 100644 --- a/webodf/tests/ops/operationtests.xml +++ b/webodf/tests/ops/operationtests.xml @@ -2135,7 +2135,7 @@ AAlice2013-08-05T12:34:07.061ZBC - + ABCD