Skip to content

Commit 59f94c6

Browse files
peitschieFriedrich W. H. Kossebau
authored andcommitted
Change step insertion/removal signaling to differ from normal signals
These events feed straight into the steps cache, and must be processed by the cache before any external consumers receive the event.
1 parent bff40e6 commit 59f94c6

9 files changed

Lines changed: 32 additions & 15 deletions

webodf/lib/ops/OdtDocument.js

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,13 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
165165
var odfContainer = odfCanvas.odfContainer(),
166166
rootNode;
167167

168-
eventNotifier.unsubscribe(ops.OdtDocument.signalStepsInserted, stepsTranslator.handleStepsInserted);
169-
eventNotifier.unsubscribe(ops.OdtDocument.signalStepsRemoved, stepsTranslator.handleStepsRemoved);
170-
171168
// TODO Replace with a neater hack for reloading the Odt tree
172169
// Once this is fixed, SelectionView.addOverlays can be removed
173170
odfContainer.setRootElement(documentElement);
174171
odfCanvas.setOdfContainer(odfContainer, true);
175172
odfCanvas.refreshCSS();
176173
rootNode = getRootNode();
177174
stepsTranslator = new ops.OdtStepsTranslator(rootNode, createPositionIterator(rootNode), filter, 500);
178-
eventNotifier.subscribe(ops.OdtDocument.signalStepsInserted, stepsTranslator.handleStepsInserted);
179-
eventNotifier.subscribe(ops.OdtDocument.signalStepsRemoved, stepsTranslator.handleStepsRemoved);
180175
};
181176

182177
/**
@@ -942,6 +937,30 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
942937
callback();
943938
};
944939

940+
/**
941+
* Process steps being inserted into the document. Will emit a steps inserted signal on
942+
* behalf of the caller
943+
* @param {!{position: !number}} args
944+
* @return {undefined}
945+
*/
946+
this.handleStepsInserted = function(args) {
947+
stepsTranslator.handleStepsInserted(args);
948+
// signal not used in webodf, but 3rd-party (NVivo)
949+
self.emit(ops.OdtDocument.signalStepsInserted, args);
950+
};
951+
952+
/**
953+
* Process steps being removed from the document. Will emit a steps removed signal on
954+
* behalf of the caller
955+
* @param {!{position: !number}} args
956+
* @return {undefined}
957+
*/
958+
this.handleStepsRemoved = function(args) {
959+
stepsTranslator.handleStepsRemoved(args);
960+
// signal not used in webodf, but 3rd-party (NVivo)
961+
self.emit(ops.OdtDocument.signalStepsRemoved, args);
962+
};
963+
945964
/**
946965
* @return {undefined}
947966
*/
@@ -951,8 +970,6 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
951970
filter = new ops.TextPositionFilter();
952971
stepUtils = new odf.StepUtils();
953972
stepsTranslator = new ops.OdtStepsTranslator(rootNode, createPositionIterator(rootNode), filter, 500);
954-
eventNotifier.subscribe(ops.OdtDocument.signalStepsInserted, stepsTranslator.handleStepsInserted);
955-
eventNotifier.subscribe(ops.OdtDocument.signalStepsRemoved, stepsTranslator.handleStepsRemoved);
956973
eventNotifier.subscribe(ops.OdtDocument.signalOperationEnd, handleOperationExecuted);
957974
eventNotifier.subscribe(ops.OdtDocument.signalProcessingBatchEnd, core.Task.processTasks);
958975
}

webodf/lib/ops/OpAddAnnotation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ ops.OpAddAnnotation = function OpAddAnnotation() {
158158
insertNodeAtPosition(odtDocument, annotationEnd, position + length);
159159
}
160160
insertNodeAtPosition(odtDocument, annotation, position);
161-
odtDocument.emit(ops.OdtDocument.signalStepsInserted, {position: position});
161+
odtDocument.handleStepsInserted({position: position});
162162

163163
// Move the cursor inside the new annotation,
164164
// by selecting the paragraph's range.

webodf/lib/ops/OpInsertImage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ ops.OpInsertImage = function OpInsertImage() {
9797
textNode.splitText(domPosition.offset) : textNode.nextSibling;
9898
frameElement = createFrameElement(odtDocument.getDOMDocument());
9999
textNode.parentNode.insertBefore(frameElement, refNode);
100-
odtDocument.emit(ops.OdtDocument.signalStepsInserted, {position: position});
100+
odtDocument.handleStepsInserted({position: position});
101101

102102
// clean up any empty text node which was created by odtDocument.getTextNodeAtStep
103103
if (textNode.length === 0) {

webodf/lib/ops/OpInsertTable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ ops.OpInsertTable = function OpInsertTable() {
157157
previousSibling = odfUtils.getParagraphElement(domPosition.textNode);
158158
rootNode.insertBefore(tableNode, previousSibling.nextSibling);
159159
// The parent table counts for 1 position, and 1 paragraph is added per cell
160-
odtDocument.emit(ops.OdtDocument.signalStepsInserted, {position: position});
160+
odtDocument.handleStepsInserted({position: position});
161161

162162
odtDocument.getOdfCanvas().refreshSize();
163163
odtDocument.emit(ops.OdtDocument.signalTableAdded, {

webodf/lib/ops/OpInsertText.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ ops.OpInsertText = function OpInsertText() {
186186
previousNode.parentNode.removeChild(previousNode);
187187
}
188188

189-
odtDocument.emit(ops.OdtDocument.signalStepsInserted, {position: position});
189+
odtDocument.handleStepsInserted({position: position});
190190

191191
if (cursor && moveCursor) {
192192
// Explicitly place the cursor in the desired position after insertion

webodf/lib/ops/OpMergeParagraph.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ ops.OpMergeParagraph = function OpMergeParagraph() {
244244
collapseRules.mergeChildrenIntoParent(sourceParagraph);
245245

246246
// Merging removes a single step between the boundary of the two paragraphs
247-
odtDocument.emit(ops.OdtDocument.signalStepsRemoved, {position: sourceStartPosition - 1});
247+
odtDocument.handleStepsRemoved({position: sourceStartPosition - 1});
248248

249249
// Downgrade trailing spaces at the end of the destination paragraph, and the beginning of the source paragraph.
250250
// These are the only two places that might need downgrading as a result of the merge.

webodf/lib/ops/OpRemoveAnnotation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ ops.OpRemoveAnnotation = function OpRemoveAnnotation() {
9090
annotationEnd.parentNode.removeChild(annotationEnd);
9191
}
9292
// The specified position is the first walkable step in the annotation. The position is always just before the first point of change
93-
odtDocument.emit(ops.OdtDocument.signalStepsRemoved, {position: position > 0 ? position - 1 : position});
93+
odtDocument.handleStepsRemoved({position: position > 0 ? position - 1 : position});
9494

9595
odtDocument.getOdfCanvas().rerenderAnnotations();
9696
odtDocument.fixCursorPositions();

webodf/lib/ops/OpRemoveText.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ ops.OpRemoveText = function OpRemoveText() {
9191
}
9292
});
9393

94-
odtDocument.emit(ops.OdtDocument.signalStepsRemoved, {position: position});
94+
odtDocument.handleStepsRemoved({position: position});
9595
odtDocument.downgradeWhitespacesAtPosition(position);
9696
odtDocument.fixCursorPositions();
9797
odtDocument.getOdfCanvas().refreshSize();

webodf/lib/ops/OpSplitParagraph.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ ops.OpSplitParagraph = function OpSplitParagraph() {
168168
if (domPosition.textNode.length === 0) {
169169
domPosition.textNode.parentNode.removeChild(domPosition.textNode);
170170
}
171-
odtDocument.emit(ops.OdtDocument.signalStepsInserted, {position: position});
171+
odtDocument.handleStepsInserted({position: position});
172172

173173
if (cursor && moveCursor) {
174174
odtDocument.moveCursor(memberid, position + 1, 0);

0 commit comments

Comments
 (0)