fix formatting bug. fixes #319 closes #320

This commit is contained in:
Kevin Jahns 2021-08-02 16:43:25 +02:00
parent 89b4320a8e
commit 4707fc46ac
2 changed files with 19 additions and 3 deletions

View File

@ -164,12 +164,13 @@ const insertNegatedAttributes = (transaction, parent, currPos, negatedAttributes
}
const doc = transaction.doc
const ownClientId = doc.clientID
let nextFormat = currPos.left
const right = currPos.right
negatedAttributes.forEach((val, key) => {
nextFormat = new Item(createID(ownClientId, getState(doc.store, ownClientId)), nextFormat, nextFormat && nextFormat.lastId, right, right && right.id, parent, null, new ContentFormat(key, val))
const left = currPos.left
const right = currPos.right
const nextFormat = new Item(createID(ownClientId, getState(doc.store, ownClientId)), left, left && left.lastId, right, right && right.id, parent, null, new ContentFormat(key, val))
nextFormat.integrate(transaction, 0)
currPos.right = nextFormat
currPos.forward()
})
}

View File

@ -168,3 +168,18 @@ export const testClone = tc => {
t.assert(cloneYxml.length === 3)
t.compare(cloneYxml.toJSON(), yxml.toJSON())
}
/**
* @param {t.TestCase} tc
*/
export const testFormattingBug = tc => {
const ydoc = new Y.Doc()
const yxml = /** @type {Y.XmlText} */ (ydoc.get('', Y.XmlText))
const delta = [
{ insert: 'A', attributes: { em: {}, strong: {} } },
{ insert: 'B', attributes: { em: {} } },
{ insert: 'C', attributes: { em: {}, strong: {} } }
]
yxml.applyDelta(delta)
t.compare(yxml.toDelta(), delta)
}