Skip to content

Commit 9534f81

Browse files
author
Friedrich W. H. Kossebau
committed
Let events about fixed up cursor positions be part of operation event stack
1 parent 0730180 commit 9534f81

11 files changed

Lines changed: 41 additions & 23 deletions

webodf/lib/gui/SessionView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ gui.SessionViewOptions = function () {
410410
var annotationViewManager = odfCanvas.getAnnotationViewManager();
411411
if (annotationViewManager) {
412412
annotationViewManager.rehighlightAnnotations();
413-
odtDocument.fixCursorPositions(); // TODO: remove this, this should not be needed. for now add return value if moved, and assert here that not.
413+
odtDocument.fixCursorPositions(false); // TODO: workaround, ideally this would not be needed
414414
}
415415
}
416416

webodf/lib/ops/OdtDocument.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
154154
initialDoc = rootElement.cloneNode(true);
155155
odfCanvas.refreshAnnotations();
156156
// workaround AnnotationViewManager not fixing up cursor positions after creating the highlighting
157-
self.fixCursorPositions();
157+
self.fixCursorPositions(false);
158158
return initialDoc;
159159
};
160160

@@ -724,8 +724,14 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
724724
* walkable positions; if not, move the cursor 1 filtered step backward
725725
* which guarantees walkable state for all cursors,
726726
* while keeping them inside the same root. An event will be raised for this cursor if it is moved
727+
* @param {!Array.<!ops.Operation.Event>|!boolean} events array to add events for moved cursors, needs to be otherwise explicitely set to false
728+
* @return {undefined}
727729
*/
728-
this.fixCursorPositions = function () {
730+
this.fixCursorPositions = function (events) {
731+
var /** @type{!Array.<!ops.OdtCursor>}*/ movedCursors = [];
732+
733+
runtime.assert(Array.isArray(events) || (typeof events === "boolean" && events === false), "second parameter to fixCursorPositions needs to be set to false or an event");
734+
729735
Object.keys(cursors).forEach(function (memberId) {
730736
var cursor = cursors[memberId],
731737
root = getRoot(cursor.getNode()),
@@ -768,9 +774,19 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
768774

769775
if (cursorMoved) {
770776
cursor.setSelectedRange(selectedRange, cursor.hasForwardSelection());
771-
eventNotifier.emit(ops.Document.signalCursorMoved, cursor);
777+
movedCursors.push(cursor);
772778
}
773779
});
780+
781+
if (events) {
782+
movedCursors.forEach(function(cursor) {
783+
events.push({ eventid: ops.Document.signalCursorMoved, args: cursor });
784+
});
785+
} else {
786+
movedCursors.forEach(function(cursor) {
787+
eventNotifier.emit(ops.Document.signalCursorMoved, cursor);
788+
});
789+
}
774790
};
775791

776792
/**

webodf/lib/ops/OpAddAnnotation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ ops.OpAddAnnotation = function OpAddAnnotation() {
174174
}
175175
// Track this annotation
176176
odtDocument.getOdfCanvas().addAnnotation(annotation);
177-
odtDocument.fixCursorPositions();
177+
odtDocument.fixCursorPositions(events);
178178
events.push({eventid: ops.OdtDocument.signalAnnotationAdded, args: { memberId: memberid, annotation: annotation }});
179179

180180
return events;

webodf/lib/ops/OpApplyDirectStyling.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ ops.OpApplyDirectStyling = function OpApplyDirectStyling() {
9292

9393
range.detach();
9494
odtDocument.getOdfCanvas().refreshCSS();
95-
odtDocument.fixCursorPositions(); // The container splits may leave the cursor in an invalid spot
95+
odtDocument.fixCursorPositions(events); // The container splits may leave the cursor in an invalid spot
9696

9797
impactedParagraphs.forEach(function (n) {
9898
events.push({

webodf/lib/ops/OpApplyHyperlink.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ ops.OpApplyHyperlink = function OpApplyHyperlink() {
112112
boundaryNodes.forEach(domUtils.normalizeTextNodes);
113113
range.detach();
114114

115-
odtDocument.fixCursorPositions();
115+
odtDocument.fixCursorPositions(events);
116116
odtDocument.getOdfCanvas().refreshSize();
117117
odtDocument.getOdfCanvas().rerenderAnnotations();
118118
modifiedParagraphs.forEach(function (paragraph) {

webodf/lib/ops/OpMergeParagraph.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ ops.OpMergeParagraph = function OpMergeParagraph() {
271271
events.push({eventid: ops.Document.signalCursorMoved, args:cursor});
272272
}
273273

274-
odtDocument.fixCursorPositions();
274+
odtDocument.fixCursorPositions(events);
275275
odtDocument.getOdfCanvas().refreshSize();
276276
// TODO: signal also the deleted paragraphs, so e.g. SessionView can clean up the EditInfo
277277
events.push({

webodf/lib/ops/OpRemoveAnnotation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ ops.OpRemoveAnnotation = function OpRemoveAnnotation() {
9595
odtDocument.handleStepsRemoved({position: position > 0 ? position - 1 : position}, events);
9696

9797
odtDocument.getOdfCanvas().rerenderAnnotations();
98-
odtDocument.fixCursorPositions();
98+
odtDocument.fixCursorPositions(events);
9999

100100
return events;
101101
};

webodf/lib/ops/OpRemoveHyperlink.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,25 @@ ops.OpRemoveHyperlink = function OpRemoveHyperlink() {
5656
var odtDocument = /**@type{ops.OdtDocument}*/(document),
5757
range = odtDocument.convertCursorToDomRange(position, length),
5858
links = odfUtils.getHyperlinkElements(range),
59-
node;
59+
node,
60+
events = [];
6061

6162
runtime.assert(links.length === 1, "The given range should only contain a single link.");
6263
node = domUtils.mergeIntoParent(/**@type{!Node}*/(links[0]));
6364
range.detach();
6465

65-
odtDocument.fixCursorPositions();
66+
odtDocument.fixCursorPositions(events);
6667
odtDocument.getOdfCanvas().refreshSize();
6768
odtDocument.getOdfCanvas().rerenderAnnotations();
68-
return [{
69+
events.push({
6970
eventid: ops.OdtDocument.signalParagraphChanged,
7071
args: {
7172
paragraphElement: odfUtils.getParagraphElement(node),
7273
memberId: memberid,
7374
timeStamp: timestamp
7475
}
75-
}];
76+
});
77+
return events;
7678
};
7779

7880
/**

webodf/lib/ops/OpRemoveText.js

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

9696
odtDocument.handleStepsRemoved({position: position}, events);
9797
odtDocument.downgradeWhitespacesAtPosition(position);
98-
odtDocument.fixCursorPositions();
98+
odtDocument.fixCursorPositions(events);
9999
odtDocument.getOdfCanvas().refreshSize();
100100
events.push({
101101
eventid: ops.OdtDocument.signalParagraphChanged,

webodf/lib/ops/OpSplitParagraph.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ ops.OpSplitParagraph = function OpSplitParagraph() {
177177
events.push({eventid: ops.Document.signalCursorMoved, args: cursor});
178178
}
179179

180-
odtDocument.fixCursorPositions();
180+
odtDocument.fixCursorPositions(events);
181181
odtDocument.getOdfCanvas().refreshSize();
182182
// mark both paragraphs as edited
183183
events.push({

0 commit comments

Comments
 (0)