Skip to content

Commit db2096f

Browse files
committed
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 d761802 commit db2096f

File tree

9 files changed

+30
-10
lines changed

9 files changed

+30
-10
lines changed

webodf/lib/ops/OdtDocument.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -941,15 +941,35 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
941941
callback();
942942
};
943943

944+
/**
945+
* Process steps being inserted into the document. Will emit a steps inserted signal on
946+
* behalf of the caller
947+
* @param {!{position: !number}} args
948+
* @return {undefined}
949+
*/
950+
this.handleStepsInserted = function(args) {
951+
stepsTranslator.handleStepsInserted(args);
952+
self.emit(ops.OdtDocument.signalStepsInserted, args);
953+
};
954+
955+
/**
956+
* Process steps being removed from the document. Will emit a steps removed signal on
957+
* behalf of the caller
958+
* @param {!{position: !number}} args
959+
* @return {undefined}
960+
*/
961+
this.handleStepsRemoved = function(args) {
962+
stepsTranslator.handleStepsRemoved(args);
963+
self.emit(ops.OdtDocument.signalStepsRemoved, args);
964+
};
965+
944966
/**
945967
* @return {undefined}
946968
*/
947969
function init() {
948970
filter = new ops.TextPositionFilter();
949971
stepUtils = new odf.StepUtils();
950972
stepsTranslator = new ops.OdtStepsTranslator(getRootNode, createPositionIterator, filter, 500);
951-
eventNotifier.subscribe(ops.OdtDocument.signalStepsInserted, stepsTranslator.handleStepsInserted);
952-
eventNotifier.subscribe(ops.OdtDocument.signalStepsRemoved, stepsTranslator.handleStepsRemoved);
953973
eventNotifier.subscribe(ops.OdtDocument.signalOperationEnd, handleOperationExecuted);
954974
eventNotifier.subscribe(ops.OdtDocument.signalProcessingBatchEnd, core.Task.processTasks);
955975
}

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
@@ -241,7 +241,7 @@ ops.OpMergeParagraph = function OpMergeParagraph() {
241241
collapseRules.mergeChildrenIntoParent(sourceParagraph);
242242

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

246246
// Downgrade trailing spaces at the end of the destination paragraph, and the beginning of the source paragraph.
247247
// 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.fixCursorPositions();
9696
odtDocument.getOdfCanvas().refreshAnnotations();

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)