Skip to content

Commit

Permalink
Merge branch 'update-attributes-on-delete' of git://github.com/ja2nic…
Browse files Browse the repository at this point in the history
…holl/yjs into ja2nicholl-update-attributes-on-delete
  • Loading branch information
dmonad committed Feb 4, 2022
2 parents d69d93f + 84e95f1 commit 04009f0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/types/YText.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ const deleteText = (transaction, currPos, length) => {
currPos.forward()
}
if (start) {
cleanupFormattingGap(transaction, start, currPos.right, startAttrs, map.copy(currPos.currentAttributes))
cleanupFormattingGap(transaction, start, currPos.right, startAttrs, currPos.currentAttributes)
}
const parent = /** @type {AbstractType<any>} */ (/** @type {Item} */ (currPos.left || currPos.right).parent)
if (parent._searchMarker) {
Expand Down
22 changes: 22 additions & 0 deletions tests/y-text.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,28 @@ export const testNotMergeEmptyLinesFormat = tc => {
])
}

/**
* @param {t.TestCase} tc
*/
export const testPreserveAttributesThroughDelete = tc => {
const ydoc = new Y.Doc()
const testText = ydoc.getText('test')
testText.applyDelta([
{ insert: 'Text' },
{ insert: '\n', attributes: { title: true } },
{ insert: '\n' }
])
testText.applyDelta([
{ retain: 4 },
{ delete: 1 },
{ retain: 1, attributes: { title: true } }
])
t.compare(testText.toDelta(), [
{ insert: 'Text' },
{ insert: '\n', attributes: { title: true } }
])
}

/**
* @param {t.TestCase} tc
*/
Expand Down

0 comments on commit 04009f0

Please sign in to comment.