|
|
@@ -11,23 +11,78 @@ import {
|
|
|
|
|
|
export function createConflict(): Conflict {
|
|
|
const conflict = new Conflict();
|
|
|
- conflict.add(InsertRowOperation, InsertRowOperation, (tc, sc) => (to, so) => {
|
|
|
+ conflict.add(InsertRowOperation, InsertRowOperation, (targetCommand, savedCommand) => (targetOperation, savedOperation) => {
|
|
|
/**
|
|
|
* 服务端插入的行在当前行的下方
|
|
|
*/
|
|
|
- if (to.getHeight() < so.getIndex()) {
|
|
|
- tc.addOperation(to);
|
|
|
- sc.addOperation(so);
|
|
|
+ if (targetOperation.getHeight() < savedOperation.getIndex()) {
|
|
|
+ savedOperation.setIndex(savedOperation.getIndex() + targetOperation.getCount());
|
|
|
+ targetCommand.addOperation(targetOperation);
|
|
|
+ savedCommand.addOperation(savedOperation);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 服务端插入的行在当前行的上方
|
|
|
*/
|
|
|
- if (to.getIndex() > so.getHeight()) {
|
|
|
- to.setIndex(to.getIndex() + so.getCount());
|
|
|
- tc.addOperation(to);
|
|
|
- sc.addOperation(so);
|
|
|
+ if (targetOperation.getIndex() > savedOperation.getHeight()) {
|
|
|
+ targetOperation.setIndex(targetOperation.getIndex() + savedOperation.getCount());
|
|
|
+ targetCommand.addOperation(targetOperation);
|
|
|
+ savedCommand.addOperation(savedOperation);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 服务端插入的行和当前行对齐
|
|
|
+ */
|
|
|
+ if (targetOperation.getIndex() === savedOperation.getIndex() && targetOperation.getHeight() === savedOperation.getHeight()) {
|
|
|
+ targetOperation.setIndex(targetOperation.getIndex() + savedOperation.getCount());
|
|
|
+ targetCommand.addOperation(targetOperation);
|
|
|
+ savedCommand.addOperation(savedOperation);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 服务端插入的行被当前行包含
|
|
|
+ */
|
|
|
+ if (targetOperation.getIndex() <= savedOperation.getIndex() && targetOperation.getHeight() >= savedOperation.getHeight()) {
|
|
|
+ let offset = savedOperation.getIndex() - targetOperation.getIndex() + savedOperation.getCount() + 1;
|
|
|
+ targetOperation.setIndex(targetOperation.getIndex() + offset);
|
|
|
+ targetCommand.addOperation(targetOperation);
|
|
|
+ savedCommand.addOperation(savedOperation);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 服务端插入的行包含当前行
|
|
|
+ */
|
|
|
+ if (targetOperation.getIndex() >= savedOperation.getIndex() && targetOperation.getHeight() <= savedOperation.getHeight()) {
|
|
|
+ let offset = targetOperation.getIndex() - savedOperation.getIndex() + savedOperation.getCount() + 1;
|
|
|
+ targetOperation.setIndex(targetOperation.getIndex() + offset);
|
|
|
+ targetCommand.addOperation(targetOperation);
|
|
|
+ savedCommand.addOperation(savedOperation);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 服务端插入的行和当前行上交叉
|
|
|
+ */
|
|
|
+ if (targetOperation.getIndex() > savedOperation.getIndex() && targetOperation.getIndex() < savedOperation.getHeight() && targetOperation.getHeight() > savedOperation.getHeight()) {
|
|
|
+ const offset = savedOperation.getHeight() - targetOperation.getIndex() + 1;
|
|
|
+ targetOperation.setIndex(targetOperation.getIndex() + offset);
|
|
|
+ targetCommand.addOperation(targetOperation);
|
|
|
+ savedCommand.addOperation(savedOperation);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 服务端插入的行和当前行下交叉
|
|
|
+ */
|
|
|
+ if (targetOperation.getIndex() < savedOperation.getIndex() && targetOperation.getHeight() > savedOperation.getIndex() && targetOperation.getHeight() < savedOperation.getHeight()) {
|
|
|
+ const offset = savedOperation.getIndex() - targetOperation.getIndex() + savedOperation.getCount() + 1;
|
|
|
+ targetOperation.setIndex(targetOperation.getIndex() + offset);
|
|
|
+ targetCommand.addOperation(targetOperation);
|
|
|
+ savedCommand.addOperation(savedOperation);
|
|
|
}
|
|
|
});
|
|
|
return conflict;
|