fix(ot): 相同用户id编辑时会出现死循环
This commit is contained in:
parent
f515f6b45c
commit
879d7eef5f
|
@ -20,7 +20,7 @@ import RangeColoring from './range-coloring';
|
||||||
import OTDoc from './doc';
|
import OTDoc from './doc';
|
||||||
import Consumer from './consumer';
|
import Consumer from './consumer';
|
||||||
import Mutation from './mutation';
|
import Mutation from './mutation';
|
||||||
import { toJSON0 } from './utils';
|
import { toJSON0, isCursorOp } from './utils';
|
||||||
import { random } from '../utils';
|
import { random } from '../utils';
|
||||||
import './index.css';
|
import './index.css';
|
||||||
|
|
||||||
|
@ -61,7 +61,20 @@ class OTModel extends EventEmitter2 implements OTInterface {
|
||||||
const operations = filterOperations(this.waitingOps);
|
const operations = filterOperations(this.waitingOps);
|
||||||
if (operations.length > 0) {
|
if (operations.length > 0) {
|
||||||
this.waitingOps = [];
|
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);
|
this.engine.history.handleRemoteOps(operations);
|
||||||
const selections = this.selection.getSelections();
|
const selections = this.selection.getSelections();
|
||||||
this.renderSelection(selections);
|
this.renderSelection(selections);
|
||||||
|
|
|
@ -173,7 +173,26 @@ export default class extends BlockPlugin<Options> {
|
||||||
const { change, node } = this.editor;
|
const { change, node } = this.editor;
|
||||||
const range = change.range.get();
|
const range = change.range.get();
|
||||||
const blockApi = this.editor.block;
|
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 block = blockApi.closest(range.startNode);
|
||||||
const parentBlock = block.parent();
|
const parentBlock = block.parent();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue