🐛 fix for #187
This commit is contained in:
parent
e04a980af1
commit
a4ce8ae07d
@ -802,10 +802,25 @@ export class YText extends AbstractType {
|
||||
}
|
||||
case ContentEmbed:
|
||||
packStr()
|
||||
ops.push({
|
||||
/**
|
||||
* @type {Object<string,any>}
|
||||
*/
|
||||
const attributes = {}
|
||||
let addAttributes = false;
|
||||
for (const [key, value] of currentAttributes) {
|
||||
addAttributes = true;
|
||||
attributes[key] = value
|
||||
}
|
||||
/**
|
||||
* @type {Object<string,any>}
|
||||
*/
|
||||
const op = {
|
||||
insert: /** @type {ContentEmbed} */ (n.content).embed
|
||||
})
|
||||
break
|
||||
}
|
||||
if(addAttributes) {
|
||||
op.attributes = attributes
|
||||
}
|
||||
ops.push(op)
|
||||
case ContentFormat:
|
||||
if (isVisible(n, snapshot)) {
|
||||
packStr()
|
||||
|
@ -158,3 +158,17 @@ export const testToJson = tc => {
|
||||
text0.insert(0, 'abc', { bold: true })
|
||||
t.assert(text0.toJSON() === 'abc', 'toJSON returns the unformatted text')
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {t.TestCase} tc
|
||||
*/
|
||||
export const testToDeltaEmbedAttributes = tc => {
|
||||
const { text0 } = init(tc, { users: 1 })
|
||||
text0.insertEmbed(0, { image: 'imageSrc.png' }, { width: 100 })
|
||||
const [delta0] = text0.toDelta();
|
||||
t.assert(!!delta0.attributes, 'toDelta correctly reads attributes')
|
||||
const { text0: text1 } = init(tc, { users: 1 })
|
||||
text1.insertEmbed(1, { image: 'imageSrc.png' })
|
||||
const [delta1] = text1.toDelta();
|
||||
t.assert(!delta1.hasOwnProperty('attributes'), 'toDelta does not set attributes key when no attributes are present')
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user