Skip to content

Commit 0730180

Browse files
author
Friedrich W. H. Kossebau
committed
Let events about added/removed steps part be part of operation event stack
1 parent 5bde046 commit 0730180

9 files changed

Lines changed: 37 additions & 22 deletions

webodf/lib/ops/OdtDocument.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -984,27 +984,35 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
984984
};
985985

986986
/**
987-
* Process steps being inserted into the document. Will emit a steps inserted signal on
988-
* behalf of the caller
987+
* Process steps being inserted into the document. Will add a steps inserted signal
988+
* to the passed events list
989989
* @param {!{position: !number}} args
990+
* @param {!Array.<!ops.Operation.Event>} events
990991
* @return {undefined}
991992
*/
992-
this.handleStepsInserted = function(args) {
993+
this.handleStepsInserted = function(args, events) {
993994
stepsTranslator.handleStepsInserted(args);
994995
// signal not used in webodf, but 3rd-party (NVivo)
995-
eventNotifier.emit(ops.OdtDocument.signalStepsInserted, args);
996+
events.push({
997+
eventid: ops.OdtDocument.signalStepsInserted,
998+
args: args
999+
});
9961000
};
9971001

9981002
/**
9991003
* Process steps being removed from the document. Will emit a steps removed signal on
10001004
* behalf of the caller
10011005
* @param {!{position: !number}} args
1006+
* @param {!Array.<!ops.Operation.Event>} events
10021007
* @return {undefined}
10031008
*/
1004-
this.handleStepsRemoved = function(args) {
1009+
this.handleStepsRemoved = function(args, events) {
10051010
stepsTranslator.handleStepsRemoved(args);
10061011
// signal not used in webodf, but 3rd-party (NVivo)
1007-
eventNotifier.emit(ops.OdtDocument.signalStepsRemoved, args);
1012+
events.push({
1013+
eventid: ops.OdtDocument.signalStepsRemoved,
1014+
args: args
1015+
});
10081016
};
10091017

10101018
/**

webodf/lib/ops/OpAddAnnotation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ ops.OpAddAnnotation = function OpAddAnnotation() {
160160
insertNodeAtPosition(odtDocument, annotationEnd, position + length);
161161
}
162162
insertNodeAtPosition(odtDocument, annotation, position);
163-
odtDocument.handleStepsInserted({position: position});
163+
odtDocument.handleStepsInserted({position: position}, events);
164164

165165
// Move the cursor inside the new annotation,
166166
// by selecting the paragraph's range.

webodf/lib/ops/OpInsertImage.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ ops.OpInsertImage = function OpInsertImage() {
8686
var odtDocument = /**@type{ops.OdtDocument}*/(document),
8787
odfCanvas = odtDocument.getOdfCanvas(),
8888
domPosition = odtDocument.getTextNodeAtStep(position, memberid),
89-
textNode, refNode, paragraphElement, frameElement;
89+
textNode, refNode, paragraphElement, frameElement,
90+
events = [];
9091

9192
if (!domPosition) {
9293
return null;
@@ -98,7 +99,7 @@ ops.OpInsertImage = function OpInsertImage() {
9899
textNode.splitText(domPosition.offset) : textNode.nextSibling;
99100
frameElement = createFrameElement(odtDocument.getDOMDocument());
100101
textNode.parentNode.insertBefore(frameElement, refNode);
101-
odtDocument.handleStepsInserted({position: position});
102+
odtDocument.handleStepsInserted({position: position}, events);
102103

103104
// clean up any empty text node which was created by odtDocument.getTextNodeAtStep
104105
if (textNode.length === 0) {
@@ -109,14 +110,16 @@ ops.OpInsertImage = function OpInsertImage() {
109110
odfCanvas.refreshCSS();
110111
odfCanvas.rerenderAnnotations();
111112

112-
return [{
113+
events.push({
113114
eventid: ops.OdtDocument.signalParagraphChanged,
114115
args: {
115116
paragraphElement: paragraphElement,
116117
memberId: memberid,
117118
timeStamp: timestamp
118119
}
119-
}];
120+
});
121+
122+
return events;
120123
};
121124

122125
/**

webodf/lib/ops/OpInsertTable.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ ops.OpInsertTable = function OpInsertTable() {
149149
domPosition = odtDocument.getTextNodeAtStep(position),
150150
rootNode = odtDocument.getRootNode(),
151151
previousSibling,
152-
tableNode;
152+
tableNode,
153+
events = [];
153154

154155
if (domPosition) {
155156
tableNode = createTableNode(odtDocument.getDOMDocument());
@@ -158,18 +159,20 @@ ops.OpInsertTable = function OpInsertTable() {
158159
previousSibling = odfUtils.getParagraphElement(domPosition.textNode);
159160
rootNode.insertBefore(tableNode, previousSibling.nextSibling);
160161
// The parent table counts for 1 position, and 1 paragraph is added per cell
161-
odtDocument.handleStepsInserted({position: position});
162+
odtDocument.handleStepsInserted({position: position}, events);
162163

163164
odtDocument.getOdfCanvas().refreshSize();
164165
odtDocument.getOdfCanvas().rerenderAnnotations();
165-
return [{
166+
events.push({
166167
eventid: ops.OdtDocument.signalTableAdded,
167168
args: {
168169
tableElement: tableNode,
169170
memberId: memberid,
170171
timeStamp: timestamp
171172
}
172-
}];
173+
});
174+
175+
return events;
173176
}
174177
return null;
175178
};

webodf/lib/ops/OpInsertText.js

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

191-
odtDocument.handleStepsInserted({position: position});
191+
odtDocument.handleStepsInserted({position: position}, events);
192192

193193
if (cursor && moveCursor) {
194194
// 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
@@ -245,7 +245,7 @@ ops.OpMergeParagraph = function OpMergeParagraph() {
245245
collapseRules.mergeChildrenIntoParent(sourceParagraph);
246246

247247
// Merging removes a single step between the boundary of the two paragraphs
248-
odtDocument.handleStepsRemoved({position: sourceStartPosition - 1});
248+
odtDocument.handleStepsRemoved({position: sourceStartPosition - 1}, events);
249249

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

webodf/lib/ops/OpRemoveAnnotation.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ ops.OpRemoveAnnotation = function OpRemoveAnnotation() {
5959
iterator = odtDocument.getIteratorAtPosition(position),
6060
container = iterator.container(),
6161
annotationNode,
62-
annotationEnd;
62+
annotationEnd,
63+
events = [];
6364

6465
while (!(container.namespaceURI === odf.Namespaces.officens
6566
&& container.localName === 'annotation')) {
@@ -91,12 +92,12 @@ ops.OpRemoveAnnotation = function OpRemoveAnnotation() {
9192
annotationEnd.parentNode.removeChild(annotationEnd);
9293
}
9394
// The specified position is the first walkable step in the annotation. The position is always just before the first point of change
94-
odtDocument.handleStepsRemoved({position: position > 0 ? position - 1 : position});
95+
odtDocument.handleStepsRemoved({position: position > 0 ? position - 1 : position}, events);
9596

9697
odtDocument.getOdfCanvas().rerenderAnnotations();
9798
odtDocument.fixCursorPositions();
9899

99-
return [];
100+
return events;
100101
};
101102

102103
/**

webodf/lib/ops/OpRemoveText.js

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

96-
odtDocument.handleStepsRemoved({position: position});
96+
odtDocument.handleStepsRemoved({position: position}, events);
9797
odtDocument.downgradeWhitespacesAtPosition(position);
9898
odtDocument.fixCursorPositions();
9999
odtDocument.getOdfCanvas().refreshSize();

webodf/lib/ops/OpSplitParagraph.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ ops.OpSplitParagraph = function OpSplitParagraph() {
170170
if (domPosition.textNode.length === 0) {
171171
domPosition.textNode.parentNode.removeChild(domPosition.textNode);
172172
}
173-
odtDocument.handleStepsInserted({position: position});
173+
odtDocument.handleStepsInserted({position: position}, events);
174174

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

0 commit comments

Comments
 (0)