fix(ot): 相同用户id编辑时会出现死循环

This commit is contained in:
yanmao 2021-11-24 18:12:48 +08:00
parent f515f6b45c
commit 879d7eef5f
2 changed files with 35 additions and 3 deletions

View File

@ -20,7 +20,7 @@ import RangeColoring from './range-coloring';
import OTDoc from './doc';
import Consumer from './consumer';
import Mutation from './mutation';
import { toJSON0 } from './utils';
import { toJSON0, isCursorOp } from './utils';
import { random } from '../utils';
import './index.css';
@ -61,7 +61,20 @@ class OTModel extends EventEmitter2 implements OTInterface {
const operations = filterOperations(this.waitingOps);
if (operations.length > 0) {
this.waitingOps = [];
this.apply(operations);
this.apply(
operations.filter((op) => {
// 过滤掉修改自身光标位置的操作
if (
isCursorOp(op) &&
op.p.includes(
`data-selection-${this.currentMember?.uuid}`,
)
) {
return false;
}
return true;
}),
);
this.engine.history.handleRemoteOps(operations);
const selections = this.selection.getSelections();
this.renderSelection(selections);

View File

@ -173,7 +173,26 @@ export default class extends BlockPlugin<Options> {
const { change, node } = this.editor;
const range = change.range.get();
const blockApi = this.editor.block;
if (!blockApi.isFirstOffset(range, 'start')) return;
const inEnd = blockApi.isLastOffset(range, 'end');
if (inEnd && !range.collapsed) {
const startBlock = blockApi.closest(range.startNode);
const endBlock = blockApi.closest(range.endNode);
const startParentBlock = startBlock.parent();
const endParentBlock = endBlock.parent();
if (
startParentBlock &&
endParentBlock &&
endParentBlock.name === 'blockquote' &&
!startParentBlock.equal(endParentBlock)
) {
endParentBlock.remove();
return;
}
}
const inFirst = blockApi.isFirstOffset(range, 'start');
if (!inFirst) return;
const block = blockApi.closest(range.startNode);
const parentBlock = block.parent();