|
@@ -10,51 +10,35 @@ import {
|
|
|
|
|
|
|
|
export function CreateConflict(): Conflict {
|
|
export function CreateConflict(): Conflict {
|
|
|
const conflict = new Conflict();
|
|
const conflict = new Conflict();
|
|
|
- conflict.add(InsertRow, InsertRow, (targetOperation, savedOperation) => {
|
|
|
|
|
|
|
+ conflict.add(RemoveRow, InsertRow, (targetOperation, savedOperation) => {
|
|
|
// 服务端插入的行在当前行的下方
|
|
// 服务端插入的行在当前行的下方
|
|
|
if (targetOperation.getHeight() <= savedOperation.getIndex()) {
|
|
if (targetOperation.getHeight() <= savedOperation.getIndex()) {
|
|
|
- // 将服务端插入的数据行向下转移
|
|
|
|
|
- const offset = savedOperation.getIndex() + targetOperation.getCount();
|
|
|
|
|
|
|
+ const offset = targetOperation.getCount();
|
|
|
savedOperation.setIndex(savedOperation.getIndex() + offset);
|
|
savedOperation.setIndex(savedOperation.getIndex() + offset);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// 服务端插入的行在当前行的上方
|
|
// 服务端插入的行在当前行的上方
|
|
|
if (targetOperation.getIndex() >= savedOperation.getHeight()) {
|
|
if (targetOperation.getIndex() >= savedOperation.getHeight()) {
|
|
|
- // 将当前插入的数据行向下转移
|
|
|
|
|
- const offset = targetOperation.getIndex() + savedOperation.getCount();
|
|
|
|
|
|
|
+ const offset = savedOperation.getCount();
|
|
|
targetOperation.setIndex(targetOperation.getIndex() + offset);
|
|
targetOperation.setIndex(targetOperation.getIndex() + offset);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// 服务端插入的行被当前行包含
|
|
// 服务端插入的行被当前行包含
|
|
|
if (targetOperation.getIndex() <= savedOperation.getIndex() && targetOperation.getHeight() >= savedOperation.getHeight()) {
|
|
if (targetOperation.getIndex() <= savedOperation.getIndex() && targetOperation.getHeight() >= savedOperation.getHeight()) {
|
|
|
- const prevSwap = new SwapData();
|
|
|
|
|
- const nextSwap = new SwapData();
|
|
|
|
|
- const currSwap = targetOperation.getBuffer();
|
|
|
|
|
- // 拆分点
|
|
|
|
|
- const splicePoint = savedOperation.getIndex() - targetOperation.getIndex();
|
|
|
|
|
// 前操作
|
|
// 前操作
|
|
|
const prevIndex = targetOperation.getIndex();
|
|
const prevIndex = targetOperation.getIndex();
|
|
|
const prevCount = savedOperation.getIndex() - targetOperation.getIndex();
|
|
const prevCount = savedOperation.getIndex() - targetOperation.getIndex();
|
|
|
// 后操作
|
|
// 后操作
|
|
|
- const nextIndex = savedOperation.getHeight();
|
|
|
|
|
|
|
+ const nextIndex = savedOperation.getHeight() - prevCount;
|
|
|
const nextCount = targetOperation.getHeight() - savedOperation.getIndex();
|
|
const nextCount = targetOperation.getHeight() - savedOperation.getIndex();
|
|
|
- // 拆分数据
|
|
|
|
|
- if (currSwap.hasData()) {
|
|
|
|
|
- prevSwap.setData(currSwap.getData().slice(0, splicePoint));
|
|
|
|
|
- nextSwap.setData(currSwap.getData().slice(splicePoint));
|
|
|
|
|
- }
|
|
|
|
|
// 拆分操作
|
|
// 拆分操作
|
|
|
- const prevOperation = new InsertRow({
|
|
|
|
|
- describe: 'InsertRow',
|
|
|
|
|
- buffer: prevSwap,
|
|
|
|
|
|
|
+ const prevOperation = new RemoveRow({
|
|
|
|
|
+ describe: 'RemoveRow',
|
|
|
index: prevIndex,
|
|
index: prevIndex,
|
|
|
count: prevCount,
|
|
count: prevCount,
|
|
|
});
|
|
});
|
|
|
- const nextOperation = new InsertRow({
|
|
|
|
|
- describe: 'InsertRow',
|
|
|
|
|
- buffer: nextSwap,
|
|
|
|
|
|
|
+ const nextOperation = new RemoveRow({
|
|
|
|
|
+ describe: 'RemoveRow',
|
|
|
index: nextIndex,
|
|
index: nextIndex,
|
|
|
count: nextCount,
|
|
count: nextCount,
|
|
|
});
|
|
});
|
|
@@ -62,51 +46,34 @@ export function CreateConflict(): Conflict {
|
|
|
targetOperation.replaceOperations(prevOperation, nextOperation);
|
|
targetOperation.replaceOperations(prevOperation, nextOperation);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// 服务端插入的行包含当前行
|
|
// 服务端插入的行包含当前行
|
|
|
if (targetOperation.getIndex() >= savedOperation.getIndex() && targetOperation.getHeight() <= savedOperation.getHeight()) {
|
|
if (targetOperation.getIndex() >= savedOperation.getIndex() && targetOperation.getHeight() <= savedOperation.getHeight()) {
|
|
|
- // 将当前插入的数据行向下转移
|
|
|
|
|
const offset = targetOperation.getIndex() - savedOperation.getIndex() + savedOperation.getCount();
|
|
const offset = targetOperation.getIndex() - savedOperation.getIndex() + savedOperation.getCount();
|
|
|
targetOperation.setIndex(targetOperation.getIndex() + offset);
|
|
targetOperation.setIndex(targetOperation.getIndex() + offset);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// 服务端插入的行和当前行上交叉
|
|
// 服务端插入的行和当前行上交叉
|
|
|
if (targetOperation.getIndex() > savedOperation.getIndex() && targetOperation.getIndex() < savedOperation.getHeight() && targetOperation.getHeight() >= savedOperation.getHeight()) {
|
|
if (targetOperation.getIndex() > savedOperation.getIndex() && targetOperation.getIndex() < savedOperation.getHeight() && targetOperation.getHeight() >= savedOperation.getHeight()) {
|
|
|
- // 将当前插入的数据行向下转移
|
|
|
|
|
const offset = targetOperation.getIndex() - savedOperation.getIndex() + savedOperation.getCount();
|
|
const offset = targetOperation.getIndex() - savedOperation.getIndex() + savedOperation.getCount();
|
|
|
targetOperation.setIndex(targetOperation.getIndex() + offset);
|
|
targetOperation.setIndex(targetOperation.getIndex() + offset);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// 服务端插入的行和当前行下交叉
|
|
// 服务端插入的行和当前行下交叉
|
|
|
if (targetOperation.getIndex() <= savedOperation.getIndex() && targetOperation.getHeight() > savedOperation.getIndex() && targetOperation.getHeight() < savedOperation.getHeight()) {
|
|
if (targetOperation.getIndex() <= savedOperation.getIndex() && targetOperation.getHeight() > savedOperation.getIndex() && targetOperation.getHeight() < savedOperation.getHeight()) {
|
|
|
- const prevSwap = new SwapData();
|
|
|
|
|
- const nextSwap = new SwapData();
|
|
|
|
|
- const currSwap = targetOperation.getBuffer();
|
|
|
|
|
- // 拆分点
|
|
|
|
|
- const splicePoint = savedOperation.getIndex() - targetOperation.getIndex();
|
|
|
|
|
// 前操作
|
|
// 前操作
|
|
|
const prevIndex = targetOperation.getIndex();
|
|
const prevIndex = targetOperation.getIndex();
|
|
|
const prevCount = savedOperation.getIndex() - targetOperation.getIndex();
|
|
const prevCount = savedOperation.getIndex() - targetOperation.getIndex();
|
|
|
// 后操作
|
|
// 后操作
|
|
|
- const nextIndex = savedOperation.getHeight();
|
|
|
|
|
|
|
+ const nextIndex = savedOperation.getHeight() - prevCount;
|
|
|
const nextCount = targetOperation.getHeight() - savedOperation.getIndex();
|
|
const nextCount = targetOperation.getHeight() - savedOperation.getIndex();
|
|
|
- // 拆分数据
|
|
|
|
|
- if (currSwap.hasData()) {
|
|
|
|
|
- prevSwap.setData(currSwap.getData().slice(0, splicePoint));
|
|
|
|
|
- nextSwap.setData(currSwap.getData().slice(splicePoint));
|
|
|
|
|
- }
|
|
|
|
|
// 拆分操作
|
|
// 拆分操作
|
|
|
- const prevOperation = new InsertRow({
|
|
|
|
|
- describe: 'InsertRow',
|
|
|
|
|
- buffer: prevSwap,
|
|
|
|
|
|
|
+ const prevOperation = new RemoveRow({
|
|
|
|
|
+ describe: 'RemoveRow',
|
|
|
index: prevIndex,
|
|
index: prevIndex,
|
|
|
count: prevCount,
|
|
count: prevCount,
|
|
|
});
|
|
});
|
|
|
- const nextOperation = new InsertRow({
|
|
|
|
|
- describe: 'InsertRow',
|
|
|
|
|
- buffer: nextSwap,
|
|
|
|
|
|
|
+ const nextOperation = new RemoveRow({
|
|
|
|
|
+ describe: 'RemoveRow',
|
|
|
index: nextIndex,
|
|
index: nextIndex,
|
|
|
count: nextCount,
|
|
count: nextCount,
|
|
|
});
|
|
});
|
|
@@ -114,40 +81,47 @@ export function CreateConflict(): Conflict {
|
|
|
targetOperation.replaceOperations(prevOperation, nextOperation);
|
|
targetOperation.replaceOperations(prevOperation, nextOperation);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
-
|
|
|
|
|
- conflict.add(RemoveRow, InsertRow, (targetOperation, savedOperation) => {
|
|
|
|
|
|
|
+ conflict.add(InsertRow, InsertRow, (targetOperation, savedOperation) => {
|
|
|
// 服务端插入的行在当前行的下方
|
|
// 服务端插入的行在当前行的下方
|
|
|
if (targetOperation.getHeight() <= savedOperation.getIndex()) {
|
|
if (targetOperation.getHeight() <= savedOperation.getIndex()) {
|
|
|
- // 将服务端插入的数据行向下转移
|
|
|
|
|
- const offset = savedOperation.getIndex() + targetOperation.getCount();
|
|
|
|
|
|
|
+ const offset = targetOperation.getCount();
|
|
|
savedOperation.setIndex(savedOperation.getIndex() + offset);
|
|
savedOperation.setIndex(savedOperation.getIndex() + offset);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// 服务端插入的行在当前行的上方
|
|
// 服务端插入的行在当前行的上方
|
|
|
if (targetOperation.getIndex() >= savedOperation.getHeight()) {
|
|
if (targetOperation.getIndex() >= savedOperation.getHeight()) {
|
|
|
- // 将当前插入的数据行向下转移
|
|
|
|
|
- const offset = targetOperation.getIndex() + savedOperation.getCount();
|
|
|
|
|
|
|
+ const offset = savedOperation.getCount();
|
|
|
targetOperation.setIndex(targetOperation.getIndex() + offset);
|
|
targetOperation.setIndex(targetOperation.getIndex() + offset);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// 服务端插入的行被当前行包含
|
|
// 服务端插入的行被当前行包含
|
|
|
if (targetOperation.getIndex() <= savedOperation.getIndex() && targetOperation.getHeight() >= savedOperation.getHeight()) {
|
|
if (targetOperation.getIndex() <= savedOperation.getIndex() && targetOperation.getHeight() >= savedOperation.getHeight()) {
|
|
|
|
|
+ const prevSwap = new SwapData();
|
|
|
|
|
+ const nextSwap = new SwapData();
|
|
|
|
|
+ const currSwap = targetOperation.getBuffer();
|
|
|
|
|
+ // 拆分点
|
|
|
|
|
+ const splicePoint = savedOperation.getIndex() - targetOperation.getIndex();
|
|
|
// 前操作
|
|
// 前操作
|
|
|
const prevIndex = targetOperation.getIndex();
|
|
const prevIndex = targetOperation.getIndex();
|
|
|
const prevCount = savedOperation.getIndex() - targetOperation.getIndex();
|
|
const prevCount = savedOperation.getIndex() - targetOperation.getIndex();
|
|
|
// 后操作
|
|
// 后操作
|
|
|
- const nextIndex = savedOperation.getHeight() - prevCount;
|
|
|
|
|
|
|
+ const nextIndex = savedOperation.getHeight();
|
|
|
const nextCount = targetOperation.getHeight() - savedOperation.getIndex();
|
|
const nextCount = targetOperation.getHeight() - savedOperation.getIndex();
|
|
|
|
|
+ // 拆分数据
|
|
|
|
|
+ if (currSwap.hasData()) {
|
|
|
|
|
+ prevSwap.setData(currSwap.getData().slice(0, splicePoint));
|
|
|
|
|
+ nextSwap.setData(currSwap.getData().slice(splicePoint));
|
|
|
|
|
+ }
|
|
|
// 拆分操作
|
|
// 拆分操作
|
|
|
- const prevOperation = new RemoveRow({
|
|
|
|
|
- describe: 'RemoveRow',
|
|
|
|
|
|
|
+ const prevOperation = new InsertRow({
|
|
|
|
|
+ describe: 'InsertRow',
|
|
|
|
|
+ buffer: prevSwap,
|
|
|
index: prevIndex,
|
|
index: prevIndex,
|
|
|
count: prevCount,
|
|
count: prevCount,
|
|
|
});
|
|
});
|
|
|
- const nextOperation = new RemoveRow({
|
|
|
|
|
- describe: 'RemoveRow',
|
|
|
|
|
|
|
+ const nextOperation = new InsertRow({
|
|
|
|
|
+ describe: 'InsertRow',
|
|
|
|
|
+ buffer: nextSwap,
|
|
|
index: nextIndex,
|
|
index: nextIndex,
|
|
|
count: nextCount,
|
|
count: nextCount,
|
|
|
});
|
|
});
|
|
@@ -155,39 +129,46 @@ export function CreateConflict(): Conflict {
|
|
|
targetOperation.replaceOperations(prevOperation, nextOperation);
|
|
targetOperation.replaceOperations(prevOperation, nextOperation);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// 服务端插入的行包含当前行
|
|
// 服务端插入的行包含当前行
|
|
|
if (targetOperation.getIndex() >= savedOperation.getIndex() && targetOperation.getHeight() <= savedOperation.getHeight()) {
|
|
if (targetOperation.getIndex() >= savedOperation.getIndex() && targetOperation.getHeight() <= savedOperation.getHeight()) {
|
|
|
- // 将当前插入的数据行向下转移
|
|
|
|
|
const offset = targetOperation.getIndex() - savedOperation.getIndex() + savedOperation.getCount();
|
|
const offset = targetOperation.getIndex() - savedOperation.getIndex() + savedOperation.getCount();
|
|
|
targetOperation.setIndex(targetOperation.getIndex() + offset);
|
|
targetOperation.setIndex(targetOperation.getIndex() + offset);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// 服务端插入的行和当前行上交叉
|
|
// 服务端插入的行和当前行上交叉
|
|
|
if (targetOperation.getIndex() > savedOperation.getIndex() && targetOperation.getIndex() < savedOperation.getHeight() && targetOperation.getHeight() >= savedOperation.getHeight()) {
|
|
if (targetOperation.getIndex() > savedOperation.getIndex() && targetOperation.getIndex() < savedOperation.getHeight() && targetOperation.getHeight() >= savedOperation.getHeight()) {
|
|
|
- // 将当前插入的数据行向下转移
|
|
|
|
|
const offset = targetOperation.getIndex() - savedOperation.getIndex() + savedOperation.getCount();
|
|
const offset = targetOperation.getIndex() - savedOperation.getIndex() + savedOperation.getCount();
|
|
|
targetOperation.setIndex(targetOperation.getIndex() + offset);
|
|
targetOperation.setIndex(targetOperation.getIndex() + offset);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// 服务端插入的行和当前行下交叉
|
|
// 服务端插入的行和当前行下交叉
|
|
|
if (targetOperation.getIndex() <= savedOperation.getIndex() && targetOperation.getHeight() > savedOperation.getIndex() && targetOperation.getHeight() < savedOperation.getHeight()) {
|
|
if (targetOperation.getIndex() <= savedOperation.getIndex() && targetOperation.getHeight() > savedOperation.getIndex() && targetOperation.getHeight() < savedOperation.getHeight()) {
|
|
|
|
|
+ const prevSwap = new SwapData();
|
|
|
|
|
+ const nextSwap = new SwapData();
|
|
|
|
|
+ const currSwap = targetOperation.getBuffer();
|
|
|
|
|
+ // 拆分点
|
|
|
|
|
+ const splicePoint = savedOperation.getIndex() - targetOperation.getIndex();
|
|
|
// 前操作
|
|
// 前操作
|
|
|
const prevIndex = targetOperation.getIndex();
|
|
const prevIndex = targetOperation.getIndex();
|
|
|
const prevCount = savedOperation.getIndex() - targetOperation.getIndex();
|
|
const prevCount = savedOperation.getIndex() - targetOperation.getIndex();
|
|
|
// 后操作
|
|
// 后操作
|
|
|
- const nextIndex = savedOperation.getHeight() - prevCount;
|
|
|
|
|
|
|
+ const nextIndex = savedOperation.getHeight();
|
|
|
const nextCount = targetOperation.getHeight() - savedOperation.getIndex();
|
|
const nextCount = targetOperation.getHeight() - savedOperation.getIndex();
|
|
|
|
|
+ // 拆分数据
|
|
|
|
|
+ if (currSwap.hasData()) {
|
|
|
|
|
+ prevSwap.setData(currSwap.getData().slice(0, splicePoint));
|
|
|
|
|
+ nextSwap.setData(currSwap.getData().slice(splicePoint));
|
|
|
|
|
+ }
|
|
|
// 拆分操作
|
|
// 拆分操作
|
|
|
- const prevOperation = new RemoveRow({
|
|
|
|
|
- describe: 'RemoveRow',
|
|
|
|
|
|
|
+ const prevOperation = new InsertRow({
|
|
|
|
|
+ describe: 'InsertRow',
|
|
|
|
|
+ buffer: prevSwap,
|
|
|
index: prevIndex,
|
|
index: prevIndex,
|
|
|
count: prevCount,
|
|
count: prevCount,
|
|
|
});
|
|
});
|
|
|
- const nextOperation = new RemoveRow({
|
|
|
|
|
- describe: 'RemoveRow',
|
|
|
|
|
|
|
+ const nextOperation = new InsertRow({
|
|
|
|
|
+ describe: 'InsertRow',
|
|
|
|
|
+ buffer: nextSwap,
|
|
|
index: nextIndex,
|
|
index: nextIndex,
|
|
|
count: nextCount,
|
|
count: nextCount,
|
|
|
});
|
|
});
|
|
@@ -195,5 +176,19 @@ export function CreateConflict(): Conflict {
|
|
|
targetOperation.replaceOperations(prevOperation, nextOperation);
|
|
targetOperation.replaceOperations(prevOperation, nextOperation);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
+ conflict.add(RemoveRow, RemoveRow, (targetOperation, savedOperation) => {
|
|
|
|
|
+ // 服务端插入的行在当前行的上方
|
|
|
|
|
+ if (targetOperation.getIndex() >= savedOperation.getHeight()) {
|
|
|
|
|
+ const offset = savedOperation.getCount();
|
|
|
|
|
+ targetOperation.setIndex(targetOperation.getIndex() - offset);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ conflict.add(InsertRow, RemoveRow, (targetOperation, savedOperation) => {
|
|
|
|
|
+ // 服务端插入的行在当前行的上方
|
|
|
|
|
+ if (targetOperation.getIndex() >= savedOperation.getHeight()) {
|
|
|
|
|
+ const offset = savedOperation.getCount();
|
|
|
|
|
+ targetOperation.setIndex(targetOperation.getIndex() - offset);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
return conflict;
|
|
return conflict;
|
|
|
}
|
|
}
|