mirror of
https://github.com/webodf/WebODF.git
synced 2026-11-30 16:47:58 +01:00
eject the text nodes that will never be traversed in
getTextNeighborhood, and in OpRemoveText: instead of searching for the current textNode in the neighborhood, start deleting from position zero.
This commit is contained in:
@@ -151,13 +151,17 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
|
||||
iteratedLength,
|
||||
advance,
|
||||
visited = false,
|
||||
i;
|
||||
inFirstNeighborhood = true,
|
||||
i,
|
||||
j;
|
||||
|
||||
advance = length > 0 ? iterator.nextPosition : iterator.previousPosition;
|
||||
iteratedLength = (currentNode.nodeType === 3 ? currentNode.data.length : 0) - iterator.text().length;
|
||||
iteratedLength = 0;
|
||||
|
||||
do {
|
||||
currentNeighborhood = iterator.textNeighborhood();
|
||||
currentNode = iterator.container();
|
||||
|
||||
if (currentNeighborhood.length && currentNode.nodeType === 3) {
|
||||
visited = false;
|
||||
for (i = 0; i < neighborhood.length; i += 1) {
|
||||
@@ -177,8 +181,27 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
|
||||
if (length < 0) {
|
||||
currentNeighborhood.reverse();
|
||||
}
|
||||
// When in the first local neighborhood, remove the elements that are in
|
||||
// a direction opposite to the length.
|
||||
if (inFirstNeighborhood) {
|
||||
for (j = 0; j < currentNeighborhood.length; j += 1) {
|
||||
if (currentNeighborhood[j] === currentNode) {
|
||||
currentNeighborhood.splice(0, j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (length < 0) {
|
||||
currentNeighborhood.splice(0, 1);
|
||||
}
|
||||
inFirstNeighborhood = false;
|
||||
}
|
||||
|
||||
neighborhood = neighborhood.concat(currentNeighborhood);
|
||||
iteratedLength += iterator.text().length;
|
||||
|
||||
for (j = 0; j < currentNeighborhood.length; j += 1) {
|
||||
iteratedLength += currentNeighborhood[j].data.length;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} while (advance() && iteratedLength < Math.abs(length));
|
||||
|
||||
@@ -75,7 +75,6 @@ ops.OpRemoveText = function OpRemoveText() {
|
||||
|
||||
this.execute = function (odtDocument) {
|
||||
var neighborhood = [],
|
||||
textNode,
|
||||
paragraphElement,
|
||||
textNodeSequence = [],
|
||||
remainingLength = Math.abs(length),
|
||||
@@ -86,22 +85,14 @@ ops.OpRemoveText = function OpRemoveText() {
|
||||
i,
|
||||
firstIndex;
|
||||
|
||||
textNode = odtDocument.getPositionInTextNode(position).textNode;
|
||||
paragraphElement = odtDocument.getParagraphElement(textNode);
|
||||
neighborhood = odtDocument.getTextNeighborhood(position, length);
|
||||
|
||||
if (neighborhood.length) {
|
||||
// Pick the index of the textNode from the starting neighborhood.
|
||||
firstIndex = neighborhood.indexOf(textNode);
|
||||
runtime.assert(firstIndex !== -1, "OpRemoveText: textNode not found in neighborhood");
|
||||
if (removalType === 'delete') {
|
||||
firstIndex += 1;
|
||||
}
|
||||
paragraphElement = odtDocument.getParagraphElement(neighborhood[0]);
|
||||
|
||||
for (i = firstIndex; i < neighborhood.length && remainingLength; i += 1) {
|
||||
for (i = 0; i < neighborhood.length && remainingLength; i += 1) {
|
||||
currentTextNode = neighborhood[i];
|
||||
currentParent = currentTextNode.parentNode;
|
||||
runtime.assert(currentParent !== undefined, "OpRemoveText: undefined currentParent");
|
||||
currentLength = currentTextNode.data.length;
|
||||
|
||||
if (currentLength <= remainingLength) {
|
||||
|
||||
Reference in New Issue
Block a user