ytext: diff should never create useless delta op
This commit is contained in:
parent
710ac31af3
commit
d039d48b3f
@ -631,36 +631,39 @@ export class YTextEvent extends YEvent {
|
|||||||
/**
|
/**
|
||||||
* @type {any}
|
* @type {any}
|
||||||
*/
|
*/
|
||||||
let op
|
let op = null
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'delete':
|
case 'delete':
|
||||||
op = { delete: deleteLen }
|
if (deleteLen > 0) {
|
||||||
|
op = { delete: deleteLen }
|
||||||
|
}
|
||||||
deleteLen = 0
|
deleteLen = 0
|
||||||
break
|
break
|
||||||
case 'insert':
|
case 'insert':
|
||||||
op = { insert }
|
if (typeof insert === 'object' || insert.length > 0) {
|
||||||
if (currentAttributes.size > 0) {
|
op = { insert }
|
||||||
op.attributes = {}
|
if (currentAttributes.size > 0) {
|
||||||
currentAttributes.forEach((value, key) => {
|
op.attributes = {}
|
||||||
if (value !== null) {
|
currentAttributes.forEach((value, key) => {
|
||||||
op.attributes[key] = value
|
if (value !== null) {
|
||||||
}
|
op.attributes[key] = value
|
||||||
})
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
insert = ''
|
insert = ''
|
||||||
break
|
break
|
||||||
case 'retain':
|
case 'retain':
|
||||||
op = { retain }
|
if (retain > 0) {
|
||||||
if (Object.keys(attributes).length > 0) {
|
op = { retain }
|
||||||
op.attributes = {}
|
if (!object.isEmpty(attributes)) {
|
||||||
for (const key in attributes) {
|
op.attributes = object.assign({}, attributes)
|
||||||
op.attributes[key] = attributes[key]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
retain = 0
|
retain = 0
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
delta.push(op)
|
if (op) delta.push(op)
|
||||||
action = null
|
action = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user