|
@@ -10,92 +10,35 @@ import {
|
|
|
|
|
|
export function CreateConflict(): Conflict {
|
|
|
const conflict = new Conflict();
|
|
|
- conflict.add(RemoveRow, InsertRow, (targetOperation, savedOperation) => {
|
|
|
- // 服务端插入的行在当前行的下方
|
|
|
- if (targetOperation.getHeight() <= savedOperation.getIndex()) {
|
|
|
- const offset = targetOperation.getCount();
|
|
|
- savedOperation.setIndex(savedOperation.getIndex() + offset);
|
|
|
- return;
|
|
|
- }
|
|
|
+ conflict.add(RemoveRow, RemoveRow, (targetOperation, savedOperation) => {
|
|
|
// 服务端插入的行在当前行的上方
|
|
|
if (targetOperation.getIndex() >= savedOperation.getHeight()) {
|
|
|
const offset = savedOperation.getCount();
|
|
|
- targetOperation.setIndex(targetOperation.getIndex() + offset);
|
|
|
- return;
|
|
|
- }
|
|
|
- // 服务端插入的行被当前行包含
|
|
|
- if (targetOperation.getIndex() <= savedOperation.getIndex() && targetOperation.getHeight() >= savedOperation.getHeight()) {
|
|
|
- // 前操作
|
|
|
- const prevIndex = targetOperation.getIndex();
|
|
|
- const prevCount = savedOperation.getIndex() - targetOperation.getIndex();
|
|
|
- // 后操作
|
|
|
- const nextIndex = savedOperation.getHeight() - prevCount;
|
|
|
- const nextCount = targetOperation.getHeight() - savedOperation.getIndex();
|
|
|
- // 拆分操作
|
|
|
- const prevOperation = new RemoveRow({
|
|
|
- describe: 'RemoveRow',
|
|
|
- index: prevIndex,
|
|
|
- count: prevCount,
|
|
|
- });
|
|
|
- const nextOperation = new RemoveRow({
|
|
|
- describe: 'RemoveRow',
|
|
|
- index: nextIndex,
|
|
|
- count: nextCount,
|
|
|
- });
|
|
|
- // 保存命令
|
|
|
- targetOperation.replaceOperations(prevOperation, nextOperation);
|
|
|
- return;
|
|
|
- }
|
|
|
- // 服务端插入的行包含当前行
|
|
|
- if (targetOperation.getIndex() >= savedOperation.getIndex() && targetOperation.getHeight() <= savedOperation.getHeight()) {
|
|
|
- const offset = targetOperation.getIndex() - savedOperation.getIndex() + savedOperation.getCount();
|
|
|
- targetOperation.setIndex(targetOperation.getIndex() + offset);
|
|
|
- return;
|
|
|
- }
|
|
|
- // 服务端插入的行和当前行上交叉
|
|
|
- if (targetOperation.getIndex() > savedOperation.getIndex() && targetOperation.getIndex() < savedOperation.getHeight() && targetOperation.getHeight() >= savedOperation.getHeight()) {
|
|
|
- const offset = targetOperation.getIndex() - savedOperation.getIndex() + savedOperation.getCount();
|
|
|
- targetOperation.setIndex(targetOperation.getIndex() + offset);
|
|
|
- return;
|
|
|
+ targetOperation.setIndex(targetOperation.getIndex() - offset);
|
|
|
}
|
|
|
- // 服务端插入的行和当前行下交叉
|
|
|
- if (targetOperation.getIndex() <= savedOperation.getIndex() && targetOperation.getHeight() > savedOperation.getIndex() && targetOperation.getHeight() < savedOperation.getHeight()) {
|
|
|
- // 前操作
|
|
|
- const prevIndex = targetOperation.getIndex();
|
|
|
- const prevCount = savedOperation.getIndex() - targetOperation.getIndex();
|
|
|
- // 后操作
|
|
|
- const nextIndex = savedOperation.getHeight() - prevCount;
|
|
|
- const nextCount = targetOperation.getHeight() - savedOperation.getIndex();
|
|
|
- // 拆分操作
|
|
|
- const prevOperation = new RemoveRow({
|
|
|
- describe: 'RemoveRow',
|
|
|
- index: prevIndex,
|
|
|
- count: prevCount,
|
|
|
- });
|
|
|
- const nextOperation = new RemoveRow({
|
|
|
- describe: 'RemoveRow',
|
|
|
- index: nextIndex,
|
|
|
- count: nextCount,
|
|
|
- });
|
|
|
- // 保存命令
|
|
|
- targetOperation.replaceOperations(prevOperation, nextOperation);
|
|
|
+ });
|
|
|
+ conflict.add(InsertRow, RemoveRow, (targetOperation, savedOperation) => {
|
|
|
+ // 服务端插入的行在当前行的上方
|
|
|
+ if (targetOperation.getIndex() >= savedOperation.getHeight()) {
|
|
|
+ const offset = savedOperation.getCount();
|
|
|
+ targetOperation.setIndex(targetOperation.getIndex() - offset);
|
|
|
}
|
|
|
});
|
|
|
conflict.add(InsertRow, InsertRow, (targetOperation, savedOperation) => {
|
|
|
- // 服务端插入的行在当前行的下方
|
|
|
- if (targetOperation.getHeight() <= savedOperation.getIndex()) {
|
|
|
- const offset = targetOperation.getCount();
|
|
|
- savedOperation.setIndex(savedOperation.getIndex() + offset);
|
|
|
+ // 服务端插入的行在当前行的上方
|
|
|
+ if (targetOperation.getIndex() > savedOperation.getHeight()) {
|
|
|
+ const offset = savedOperation.getCount();
|
|
|
+ targetOperation.setIndex(targetOperation.getIndex() + offset);
|
|
|
return;
|
|
|
}
|
|
|
- // 服务端插入的行在当前行的上方
|
|
|
- if (targetOperation.getIndex() >= savedOperation.getHeight()) {
|
|
|
+ // 服务端插入的行和当前行的起始位置对齐
|
|
|
+ if (targetOperation.getIndex() === savedOperation.getIndex()) {
|
|
|
const offset = savedOperation.getCount();
|
|
|
targetOperation.setIndex(targetOperation.getIndex() + offset);
|
|
|
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();
|
|
@@ -130,19 +73,13 @@ export function CreateConflict(): Conflict {
|
|
|
return;
|
|
|
}
|
|
|
// 服务端插入的行包含当前行
|
|
|
- if (targetOperation.getIndex() >= savedOperation.getIndex() && targetOperation.getHeight() <= savedOperation.getHeight()) {
|
|
|
- const offset = targetOperation.getIndex() - savedOperation.getIndex() + savedOperation.getCount();
|
|
|
- targetOperation.setIndex(targetOperation.getIndex() + offset);
|
|
|
- return;
|
|
|
- }
|
|
|
- // 服务端插入的行和当前行上交叉
|
|
|
- if (targetOperation.getIndex() > savedOperation.getIndex() && targetOperation.getIndex() < savedOperation.getHeight() && targetOperation.getHeight() >= savedOperation.getHeight()) {
|
|
|
- const offset = targetOperation.getIndex() - savedOperation.getIndex() + savedOperation.getCount();
|
|
|
- targetOperation.setIndex(targetOperation.getIndex() + offset);
|
|
|
+ if (targetOperation.getIndex() > savedOperation.getIndex() && targetOperation.getHeight() < savedOperation.getHeight()) {
|
|
|
+ const offset = savedOperation.getIndex() + savedOperation.getCount();
|
|
|
+ targetOperation.setIndex(targetOperation.getIndex() - offset);
|
|
|
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();
|
|
@@ -175,18 +112,79 @@ export function CreateConflict(): Conflict {
|
|
|
// 保存命令
|
|
|
targetOperation.replaceOperations(prevOperation, nextOperation);
|
|
|
}
|
|
|
- });
|
|
|
- conflict.add(RemoveRow, RemoveRow, (targetOperation, savedOperation) => {
|
|
|
- // 服务端插入的行在当前行的上方
|
|
|
- if (targetOperation.getIndex() >= savedOperation.getHeight()) {
|
|
|
- const offset = savedOperation.getCount();
|
|
|
+ // 服务端插入的行和当前行上交叉
|
|
|
+ if (targetOperation.getIndex() > savedOperation.getIndex() && targetOperation.getIndex() < savedOperation.getHeight() && targetOperation.getHeight() >= savedOperation.getHeight()) {
|
|
|
+ const offset = savedOperation.getIndex() + savedOperation.getCount();
|
|
|
targetOperation.setIndex(targetOperation.getIndex() - offset);
|
|
|
}
|
|
|
});
|
|
|
- conflict.add(InsertRow, RemoveRow, (targetOperation, savedOperation) => {
|
|
|
+ conflict.add(RemoveRow, InsertRow, (targetOperation, savedOperation) => {
|
|
|
// 服务端插入的行在当前行的上方
|
|
|
if (targetOperation.getIndex() >= savedOperation.getHeight()) {
|
|
|
const offset = savedOperation.getCount();
|
|
|
+ targetOperation.setIndex(targetOperation.getIndex() + offset);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 服务端插入的行和当前行的起始位置对齐
|
|
|
+ if (targetOperation.getIndex() === savedOperation.getIndex()) {
|
|
|
+ const offset = savedOperation.getCount();
|
|
|
+ targetOperation.setIndex(targetOperation.getIndex() + offset);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 服务端插入的行被当前行包含
|
|
|
+ if (targetOperation.getIndex() < savedOperation.getIndex() && targetOperation.getHeight() > savedOperation.getHeight()) {
|
|
|
+ // 前操作
|
|
|
+ const prevIndex = targetOperation.getIndex();
|
|
|
+ const prevCount = savedOperation.getIndex() - targetOperation.getIndex();
|
|
|
+ // 后操作
|
|
|
+ const nextIndex = savedOperation.getHeight();
|
|
|
+ const nextCount = targetOperation.getHeight() - savedOperation.getIndex();
|
|
|
+ // 拆分操作
|
|
|
+ const prevOperation = new RemoveRow({
|
|
|
+ describe: 'RemoveRow',
|
|
|
+ index: prevIndex,
|
|
|
+ count: prevCount,
|
|
|
+ });
|
|
|
+ const nextOperation = new RemoveRow({
|
|
|
+ describe: 'RemoveRow',
|
|
|
+ index: nextIndex,
|
|
|
+ count: nextCount,
|
|
|
+ });
|
|
|
+ // 保存命令
|
|
|
+ targetOperation.replaceOperations(prevOperation, nextOperation);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 服务端插入的行包含当前行
|
|
|
+ if (targetOperation.getIndex() > savedOperation.getIndex() && targetOperation.getHeight() < savedOperation.getHeight()) {
|
|
|
+ const offset = savedOperation.getIndex() + savedOperation.getCount();
|
|
|
+ targetOperation.setIndex(targetOperation.getIndex() - offset);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 服务端插入的行和当前行下交叉
|
|
|
+ if (targetOperation.getIndex() < savedOperation.getIndex() && targetOperation.getHeight() > savedOperation.getIndex() && targetOperation.getHeight() <= savedOperation.getHeight()) {
|
|
|
+ // 前操作
|
|
|
+ const prevIndex = targetOperation.getIndex();
|
|
|
+ const prevCount = savedOperation.getIndex() - targetOperation.getIndex();
|
|
|
+ // 后操作
|
|
|
+ const nextIndex = savedOperation.getHeight();
|
|
|
+ const nextCount = targetOperation.getHeight() - savedOperation.getIndex();
|
|
|
+ // 拆分操作
|
|
|
+ const prevOperation = new RemoveRow({
|
|
|
+ describe: 'RemoveRow',
|
|
|
+ index: prevIndex,
|
|
|
+ count: prevCount,
|
|
|
+ });
|
|
|
+ const nextOperation = new RemoveRow({
|
|
|
+ describe: 'RemoveRow',
|
|
|
+ index: nextIndex,
|
|
|
+ count: nextCount,
|
|
|
+ });
|
|
|
+ // 保存命令
|
|
|
+ targetOperation.replaceOperations(prevOperation, nextOperation);
|
|
|
+ }
|
|
|
+ // 服务端插入的行和当前行上交叉
|
|
|
+ if (targetOperation.getIndex() > savedOperation.getIndex() && targetOperation.getIndex() < savedOperation.getHeight() && targetOperation.getHeight() >= savedOperation.getHeight()) {
|
|
|
+ const offset = savedOperation.getIndex() + savedOperation.getCount();
|
|
|
targetOperation.setIndex(targetOperation.getIndex() - offset);
|
|
|
}
|
|
|
});
|