diff --git a/webodf/lib/core/PositionIterator.js b/webodf/lib/core/PositionIterator.js
index 078756f9..940f089b 100644
--- a/webodf/lib/core/PositionIterator.js
+++ b/webodf/lib/core/PositionIterator.js
@@ -160,18 +160,19 @@ core.PositionIterator = function PositionIterator(root, whatToShow, filter,
startNode = walker.currentNode,
n,
text,
- prevText = false;
+ nextText = false;
if (currentPos === 1) {
n = walker.lastChild();
} else {
n = walker.previousSibling();
}
while (n) {
- text = n.nodeType === 3;
- if (!text || !prevText) { // neighboring texts count as 1 position
+ // neighboring texts count as 1 position
+ text = (n.nodeType === 3) ? n : null;
+ if (text === null || text.nextSibling !== nextText) {
c += 1;
}
- prevText = text;
+ nextText = text;
n = walker.previousSibling();
}
walker.currentNode = startNode;
@@ -243,13 +244,6 @@ core.PositionIterator = function PositionIterator(root, whatToShow, filter,
} else {
currentPos = 0;
}
- // jiggle the position to make sure it is at an allowed offset
- if (self.nextPosition()) {
- self.previousPosition();
- }
- if (self.previousPosition()) {
- self.nextPosition();
- }
return true;
};
/**
diff --git a/webodf/tests/core/PositionIteratorTests.js b/webodf/tests/core/PositionIteratorTests.js
index 6a10140e..9ac4e18c 100644
--- a/webodf/tests/core/PositionIteratorTests.js
+++ b/webodf/tests/core/PositionIteratorTests.js
@@ -216,7 +216,7 @@ core.PositionIteratorTests = function PositionIteratorTests(runner) {
}
function testPositions(count) {
var n = 0, i, it = t.iterator, ok = true;
- while (it.nextPosition()) {
+ while (it.nextPosition() && n <= count) {
t.c1 = it.container();
t.o1 = it.offset();
it.setPosition(t.c1, t.o1);
diff --git a/webodf/tests/tests.js b/webodf/tests/tests.js
index fc9730e6..8ba92f39 100644
--- a/webodf/tests/tests.js
+++ b/webodf/tests/tests.js
@@ -62,12 +62,14 @@ if (runtime.type() === "BrowserRuntime") {
// tests.push(core.CursorTests);
// tests.push(gui.XMLEditTests);
}
+/*
tests = [];
if (runtime.getDOMImplementation() && runtime.parseXML("").createRange) {
-// tests.push(core.PositionIteratorTests);
-// tests.push(gui.SelectionMoverTests);
+ tests.push(core.PositionIteratorTests);
+ tests.push(gui.SelectionMoverTests);
tests.push(gui.AvatarTests);
}
+*/
var tester = new core.UnitTester();
/**
* @param {!Array.} tests