Skip to content

Commit cf6ab24

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 e9b41aa commit cf6ab24

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
@@ -131,18 +131,13 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
131131
var odfContainer = odfCanvas.odfContainer(),
132132
rootNode;
133133

134-
eventNotifier.unsubscribe(ops.OdtDocument.signalStepsInserted, stepsTranslator.handleStepsInserted);
135-
eventNotifier.unsubscribe(ops.OdtDocument.signalStepsRemoved, stepsTranslator.handleStepsRemoved);
136-
137134
// TODO Replace with a neater hack for reloading the Odt tree
138135
// Once this is fixed, SelectionView.addOverlays can be removed
139136
odfContainer.setRootElement(documentElement);
140137
odfCanvas.setOdfContainer(odfContainer, true);
141138
odfCanvas.refreshCSS();
142139
rootNode = getRootNode();
143140
stepsTranslator = new ops.OdtStepsTranslator(rootNode, createPositionIterator(rootNode), filter, 500);
144-
eventNotifier.subscribe(ops.OdtDocument.signalStepsInserted, stepsTranslator.handleStepsInserted);
145-
eventNotifier.subscribe(ops.OdtDocument.signalStepsRemoved, stepsTranslator.handleStepsRemoved);
146141
};
147142

148143
/**
@@ -939,6 +934,30 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
939934
callback();
940935
};
941936

937+
/**
938+
* Process steps being inserted into the document. Will emit a steps inserted signal on
939+
* behalf of the caller
940+
* @param {!{position: !number}} args
941+
* @return {undefined}
942+
*/
943+
this.handleStepsInserted = function(args) {
944+
stepsTranslator.handleStepsInserted(args);
945+
// signal not used in webodf, but 3rd-party (NVivo)
946+
self.emit(ops.OdtDocument.signalStepsInserted, args);
947+
};
948+
949+
/**
950+
* Process steps being removed from the document. Will emit a steps removed signal on
951+
* behalf of the caller
952+
* @param {!{position: !number}} args
953+
* @return {undefined}
954+
*/
955+
this.handleStepsRemoved = function(args) {
956+
stepsTranslator.handleStepsRemoved(args);
957+
// signal not used in webodf, but 3rd-party (NVivo)
958+
self.emit(ops.OdtDocument.signalStepsRemoved, args);
959+
};
960+
942961
/**
943962
* @return {undefined}
944963
*/
@@ -948,8 +967,6 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
948967
filter = new ops.TextPositionFilter();
949968
stepUtils = new odf.StepUtils();
950969
stepsTranslator = new ops.OdtStepsTranslator(rootNode, createPositionIterator(rootNode), filter, 500);
951-
eventNotifier.subscribe(ops.OdtDocument.signalStepsInserted, stepsTranslator.handleStepsInserted);
952-
eventNotifier.subscribe(ops.OdtDocument.signalStepsRemoved, stepsTranslator.handleStepsRemoved);
953970
eventNotifier.subscribe(ops.OdtDocument.signalOperationEnd, handleOperationExecuted);
954971
eventNotifier.subscribe(ops.OdtDocument.signalProcessingBatchEnd, core.Task.processTasks);
955972
}

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)