mirror of
https://github.com/webodf/WebODF.git
synced 2026-11-30 16:47:58 +01:00
Update other references to be aware of getMemberIds
working for all members, and not just cursors Adds a new OdtDocument.hasMember method
This commit is contained in:
@@ -84,6 +84,10 @@ define("webodf/editor/plugins/bella/Bella", [
|
||||
ops = [];
|
||||
|
||||
members.forEach(function (memberId) {
|
||||
if (!odtDocument.getCursor(memberId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var selection = odtDocument.getCursorSelection(memberId),
|
||||
selectionType = odtDocument.getCursor(memberId).getSelectionType(),
|
||||
op = new webodf.ops.OpMoveCursor();
|
||||
@@ -250,4 +254,4 @@ define("webodf/editor/plugins/bella/Bella", [
|
||||
}
|
||||
|
||||
return Bella;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -62,6 +62,7 @@ define("webodf/editor/plugins/bella/DocumentValidator", function() {
|
||||
var root = odtDocument.getRootNode(),
|
||||
stepIterator = odtDocument.createStepIterator(root, 0, [odtDocument.getPositionFilter()], root);
|
||||
|
||||
// In a Bella environment each memberid has a cursor
|
||||
odtDocument.getMemberIds().forEach(function (memberId) {
|
||||
var cursor = odtDocument.getCursor(memberId);
|
||||
stepIterator.setPosition(cursor.getNode(), 0);
|
||||
@@ -159,4 +160,4 @@ define("webodf/editor/plugins/bella/DocumentValidator", function() {
|
||||
}
|
||||
|
||||
return DocumentValidator;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -504,7 +504,9 @@ gui.TrivialUndoManager = function TrivialUndoManager(defaultRules) {
|
||||
if (moved) {
|
||||
// Need to reset the odt document cursor list back to nil so new cursors are correctly re-registered
|
||||
document.getMemberIds().forEach(function (memberid) {
|
||||
document.removeCursor(memberid);
|
||||
if (document.hasCursor(memberid)) {
|
||||
document.removeCursor(memberid);
|
||||
}
|
||||
});
|
||||
// Only do actual work if moveBackward does something to the undo stacks
|
||||
document.setDocumentElement(/**@type{!Element}*/(initialDoc.cloneNode(true)));
|
||||
|
||||
@@ -91,6 +91,12 @@ ops.Document.prototype.createRootFilter = function (inputMemberId) { "use strict
|
||||
* @return {!core.PositionIterator}
|
||||
*/
|
||||
ops.Document.prototype.createPositionIterator = function (rootNode) { "use strict"; };
|
||||
/**
|
||||
* @param {!string} memberid
|
||||
* @return {!boolean}
|
||||
*/
|
||||
ops.Document.prototype.hasCursor = function (memberid) { "use strict"; };
|
||||
|
||||
/**@const*/
|
||||
ops.Document.signalCursorAdded = "cursor/added";
|
||||
/**@const*/
|
||||
|
||||
@@ -814,6 +814,13 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
|
||||
return cursors[memberid];
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {!string} memberid
|
||||
* @return {!boolean}
|
||||
*/
|
||||
this.hasCursor = function (memberid) {
|
||||
return cursors.hasOwnProperty(memberid);
|
||||
};
|
||||
/**
|
||||
* @return {!Array.<string>}
|
||||
*/
|
||||
|
||||
@@ -32,11 +32,13 @@
|
||||
gui.TrivialUndoManagerTests = function TrivialUndoManagerTests(runner) {
|
||||
"use strict";
|
||||
var t, testarea,
|
||||
r = runner;
|
||||
r = runner,
|
||||
member,
|
||||
cursor;
|
||||
|
||||
function cursor(id) {
|
||||
return { getMemberId: function () { return id; } };
|
||||
}
|
||||
cursor = member = function (id) {
|
||||
return { getMemberId: function () { return id; } };
|
||||
};
|
||||
|
||||
/**
|
||||
* @param rootElement
|
||||
@@ -61,11 +63,21 @@ gui.TrivialUndoManagerTests = function TrivialUndoManagerTests(runner) {
|
||||
this.setRootElement = noOp;
|
||||
this.setOdfContainer = noOp;
|
||||
this.cursors = [cursor("1")];
|
||||
this.members = [member("1")];
|
||||
this.getMemberIds = function () {
|
||||
return self.cursors.map(function (cursor) {
|
||||
return cursor.getMemberId();
|
||||
return self.members.map(function (member) {
|
||||
return member.getMemberId();
|
||||
});
|
||||
};
|
||||
this.hasCursor = function (memberid) {
|
||||
var i;
|
||||
for (i = 0; i < self.cursors.length; i += 1) {
|
||||
if (self.cursors[i].getMemberId() === memberid) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
this.getDocumentElement = function () { return rootElement; };
|
||||
this.getRootNode = function () { return rootElement; };
|
||||
this.getDOMDocument = function () { return rootElement.ownerDocument; };
|
||||
@@ -195,6 +207,7 @@ gui.TrivialUndoManagerTests = function TrivialUndoManagerTests(runner) {
|
||||
}
|
||||
|
||||
function setInitialState_AllCursorsMaintainedWhenCalledMultipleTimes() {
|
||||
t.mock.members.push(member(2));
|
||||
t.mock.cursors.push(cursor(2));
|
||||
t.manager.onOperationExecuted(create(new ops.OpMoveCursor(), {timestamp: 1, memberid: 1}));
|
||||
t.manager.onOperationExecuted(create(new ops.OpMoveCursor(), {timestamp: 2, memberid: 2}));
|
||||
@@ -362,6 +375,7 @@ gui.TrivialUndoManagerTests = function TrivialUndoManagerTests(runner) {
|
||||
t.manager.onOperationExecuted(create(new ops.OpMoveCursor(), {timestamp: 5, memberid: 1}));
|
||||
t.manager.onOperationExecuted(create(new ops.OpMoveCursor(), {timestamp: 6, memberid: 2}));
|
||||
|
||||
t.mock.members = [member(2)];
|
||||
t.mock.cursors = [cursor(2)];
|
||||
t.manager.initialize();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user