From bf338d8040011b63caab08d7a901058a13335b25 Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Thu, 2 Mar 2023 19:08:01 +0100 Subject: [PATCH] fix attribute update issue - fixes #503 --- src/types/YText.js | 10 +- tests/y-text.tests.js | 1235 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 1242 insertions(+), 3 deletions(-) diff --git a/src/types/YText.js b/src/types/YText.js index d1cdf781..83b02aa6 100644 --- a/src/types/YText.js +++ b/src/types/YText.js @@ -367,15 +367,16 @@ const cleanupFormattingGap = (transaction, start, curr, startAttributes, currAtt const endAttributes = map.copy(currAttributes) while (end && (!end.countable || end.deleted)) { if (!end.deleted && end.content.constructor === ContentFormat) { + // @todo should set endAttributes[end.key] = end and then compare identities instead of values updateCurrentAttributes(endAttributes, /** @type {ContentFormat} */ (end.content)) } end = end.right } let cleanups = 0 - let reachedEndOfCurr = false + let reachedCurr = false while (start !== end) { if (curr === start) { - reachedEndOfCurr = true + reachedCurr = true } if (!start.deleted) { const content = start.content @@ -387,7 +388,7 @@ const cleanupFormattingGap = (transaction, start, curr, startAttributes, currAtt // Either this format is overwritten or it is not necessary because the attribute already existed. start.delete(transaction) cleanups++ - if (!reachedEndOfCurr && (currAttributes.get(key) || null) === value && (startAttributes.get(key) || null) !== value) { + if (!reachedCurr && (currAttributes.get(key) || null) === value && startAttrValue !== value) { if (startAttrValue === null) { currAttributes.delete(key) } else { @@ -395,6 +396,9 @@ const cleanupFormattingGap = (transaction, start, curr, startAttributes, currAtt } } } + if (!reachedCurr && !start.deleted) { + updateCurrentAttributes(currAttributes, /** @type {ContentFormat} */ (content)) + } break } } diff --git a/tests/y-text.tests.js b/tests/y-text.tests.js index 48622673..cd44142f 100644 --- a/tests/y-text.tests.js +++ b/tests/y-text.tests.js @@ -412,6 +412,1241 @@ export const testDeltaBug = _tc => { t.compare(result, expectedResult) } +/** + * https://github.com/yjs/yjs/issues/503 + * @param {t.TestCase} _tc + */ +export const testDeltaBug2 = _tc => { + const initialContent = [ + { insert: "Thomas' section" }, + { + insert: '\n', + attributes: { 'block-id': 'block-61ae80ac-a469-4eae-bac9-3b6a2c380118' } + }, + { + insert: '\n', + attributes: { 'block-id': 'block-d265d93f-1cc7-40ee-bb58-8270fca2619f' } + }, + { insert: '123' }, + { + insert: '\n', + attributes: { + 'block-id': 'block-592a7bee-76a3-4e28-9c25-7a84344f8813', + list: { list: 'toggled', 'toggle-id': 'list-66xfft' } + } + }, + { insert: '456' }, + { + insert: '\n', + attributes: { + indent: 1, + 'block-id': 'block-3ee2bd70-b97f-45b2-9115-f1e8910235b1', + list: { list: 'toggled', 'toggle-id': 'list-6vh0t0' } + } + }, + { insert: '789' }, + { + insert: '\n', + attributes: { + indent: 1, + 'block-id': 'block-78150cf3-9bb5-4dea-a6f5-0ce1d2a98b9c', + list: { list: 'toggled', 'toggle-id': 'list-7jr0l2' } + } + }, + { insert: '901' }, + { + insert: '\n', + attributes: { + indent: 1, + 'block-id': 'block-13c6416f-f522-41d5-9fd4-ce4eb1cde5ba', + list: { list: 'toggled', 'toggle-id': 'list-7uk8qu' } + } + }, + { + insert: { + slash_command: { + id: 'doc_94zq-2436', + sessionId: 'nkwc70p2j', + replace: '/' + } + } + }, + { + insert: '\n', + attributes: { 'block-id': 'block-8a1d2bb6-23c2-4bcf-af3c-3919ffea1697' } + }, + { insert: '\n\n', attributes: { 'table-col': { width: '150' } } }, + { + insert: '\n', + attributes: { 'table-col': { width: '150' } } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-84ec3ea4-da6a-4e03-b430-0e5f432936a9', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-blmd4s', + cell: 'cell-m0u5za' + }, + row: 'row-blmd4s', + cell: 'cell-m0u5za', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-83144ca8-aace-401e-8aa5-c05928a8ccf0', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-blmd4s', + cell: 'cell-1v8s8t' + }, + row: 'row-blmd4s', + cell: 'cell-1v8s8t', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-9a493387-d27f-4b58-b2f7-731dfafda32a', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-blmd4s', + cell: 'cell-126947' + }, + row: 'row-blmd4s', + cell: 'cell-126947', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-3484f86e-ae42-440f-8de6-857f0d8011ea', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-hmmljo', + cell: 'cell-wvutl9' + }, + row: 'row-hmmljo', + cell: 'cell-wvutl9', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-d4e0b741-9dea-47a5-85e1-4ded0efbc89d', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-hmmljo', + cell: 'cell-nkablr' + }, + row: 'row-hmmljo', + cell: 'cell-nkablr', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-352f0d5a-d1b9-422f-b136-4bacefd00b1a', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-hmmljo', + cell: 'cell-n8xtd0' + }, + row: 'row-hmmljo', + cell: 'cell-n8xtd0', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-95823e57-f29c-44cf-a69d-2b4494b7144b', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-ev4xwq', + cell: 'cell-ua9bvu' + }, + row: 'row-ev4xwq', + cell: 'cell-ua9bvu', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-cde5c027-15d3-4780-9e76-1e1a9d97a8e8', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-ev4xwq', + cell: 'cell-7bwuvk' + }, + row: 'row-ev4xwq', + cell: 'cell-7bwuvk', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-11a23ed4-b04d-4e45-8065-8120889cd4a4', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-ev4xwq', + cell: 'cell-aouka5' + }, + row: 'row-ev4xwq', + cell: 'cell-aouka5', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { 'block-id': 'block-15b4483c-da98-4ded-91d3-c3d6ebc82582' } + }, + { insert: { divider: true } }, + { + insert: '\n', + attributes: { 'block-id': 'block-68552c8e-b57b-4f4a-9f36-6cc1ef6b3461' } + }, + { insert: 'jklasjdf' }, + { + insert: '\n', + attributes: { + 'block-id': 'block-c8b2df7d-8ec5-4dd4-81f1-8d8efc40b1b4', + list: { list: 'toggled', 'toggle-id': 'list-9ss39s' } + } + }, + { insert: 'asdf' }, + { + insert: '\n', + attributes: { + 'block-id': 'block-4f252ceb-14da-49ae-8cbd-69a701d18e2a', + list: { list: 'toggled', 'toggle-id': 'list-uvo013' } + } + }, + { insert: 'adg' }, + { + insert: '\n', + attributes: { + 'block-id': 'block-ccb9b72e-b94d-45a0-aae4-9b0a1961c533', + list: { list: 'toggled', 'toggle-id': 'list-k53iwe' } + } + }, + { insert: 'asdfasdfasdf' }, + { + insert: '\n', + attributes: { + 'block-id': 'block-ccb9b72e-b94d-45a0-aae4-9b0a1961c533', + list: { list: 'none' }, + indent: 1 + } + }, + { insert: 'asdf' }, + { + insert: '\n', + attributes: { + 'block-id': 'block-f406f76d-f338-4261-abe7-5c9131f7f1ad', + list: { list: 'toggled', 'toggle-id': 'list-en86ur' } + } + }, + { + insert: '\n', + attributes: { 'block-id': 'block-be18141c-9b6b-434e-8fd0-2c214437d560' } + }, + { + insert: '\n', + attributes: { 'block-id': 'block-36922db3-4af5-48a1-9ea4-0788b3b5d7cf' } + }, + { insert: { table_content: true } }, + { insert: ' ' }, + { + insert: { + slash_command: { + id: 'doc_94zq-2436', + sessionId: 'hiyrt6fny', + replace: '/' + } + } + }, + { + insert: '\n', + attributes: { 'block-id': 'block-9d6566a1-be55-4e20-999a-b990bc15e143' } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-4b545085-114d-4d07-844c-789710ec3aab', + layout: + '12d887e1-d1a2-4814-a1a3-0c904e950b46_1185cd29-ef1b-45d5-8fda-51a70b704e64', + 'layout-width': '0.25' + } + }, + { + insert: '\n', + attributes: { + + 'block-id': 'block-4d3f2321-33d1-470e-9b7c-d5a683570148', + layout: + '12d887e1-d1a2-4814-a1a3-0c904e950b46_75523ea3-c67f-4f5f-a85f-ac7c8fc0a992', + 'layout-width': '0.5' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-4c7ae1e6-758e-470f-8d7c-ae0325e4ee8a', + layout: + '12d887e1-d1a2-4814-a1a3-0c904e950b46_54c740ef-fd7b-48c6-85aa-c14e1bfc9297', + 'layout-width': '0.25' + } + }, + { + insert: '\n', + attributes: { 'block-id': 'block-2d6ff0f4-ff00-42b7-a8e2-b816463d8fb5' } + }, + { insert: { divider: true } }, + { + insert: '\n', + attributes: { 'table-col': { width: '150' } } + }, + { insert: '\n', attributes: { 'table-col': { width: '154' } } }, + { + insert: '\n', + attributes: { 'table-col': { width: '150' } } + }, + + { + insert: '\n', + attributes: { + 'block-id': 'block-38545d56-224b-464c-b779-51fcec24dbbf', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-q0qfck', + cell: 'cell-hmapv4' + }, + row: 'row-q0qfck', + cell: 'cell-hmapv4', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-d413a094-5f52-4fd4-a4aa-00774f6fdb44', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-q0qfck', + cell: 'cell-c0czb2' + }, + row: 'row-q0qfck', + cell: 'cell-c0czb2', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-ff855cbc-8871-4e0a-9ba7-de0c1c2aa585', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-q0qfck', + cell: 'cell-hcpqmm' + }, + row: 'row-q0qfck', + cell: 'cell-hcpqmm', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-4841e6ee-fef8-4473-bf04-f5ba62db17f0', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-etopyl', + cell: 'cell-0io73v' + }, + row: 'row-etopyl', + cell: 'cell-0io73v', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-adeec631-d4fe-4f38-9d5e-e67ba068bd24', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-etopyl', + cell: 'cell-gt2waa' + }, + row: 'row-etopyl', + cell: 'cell-gt2waa', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-d38a7308-c858-4ce0-b1f3-0f9092384961', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-etopyl', + cell: 'cell-os9ksy' + }, + row: 'row-etopyl', + cell: 'cell-os9ksy', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-a9df6568-1838-40d1-9d16-3c073b6ce169', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-0jwjg3', + cell: 'cell-hbx9ri' + }, + row: 'row-0jwjg3', + cell: 'cell-hbx9ri', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-e26a0cf2-fe62-44a5-a4ca-8678a56d62f1', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-0jwjg3', + cell: 'cell-yg5m2w' + }, + row: 'row-0jwjg3', + cell: 'cell-yg5m2w', + rowspan: '1', + colspan: '1' + } + }, + { insert: 'a' }, + { + insert: '\n', + attributes: { + 'block-id': 'block-bfbc5ac2-7417-44b9-9aa5-8e36e4095627', + list: { + rowspan: '1', + colspan: '1', + row: 'row-0jwjg3', + cell: 'cell-1azhl2', + list: 'ordered' + }, + rowspan: '1', + colspan: '1', + row: 'row-0jwjg3', + cell: 'cell-1azhl2' + } + }, + { insert: 'b' }, + { + insert: '\n', + attributes: { + 'block-id': 'block-f011c089-6389-47c0-8396-7477a29aa56f', + list: { + rowspan: '1', + colspan: '1', + row: 'row-0jwjg3', + cell: 'cell-1azhl2', + list: 'ordered' + }, + rowspan: '1', + colspan: '1', + row: 'row-0jwjg3', + cell: 'cell-1azhl2' + } + }, + { insert: 'c' }, + { + insert: '\n', + attributes: { + 'block-id': 'block-4497788d-1e02-4fd5-a80a-48b61a6185cb', + list: { + rowspan: '1', + colspan: '1', + row: 'row-0jwjg3', + cell: 'cell-1azhl2', + list: 'ordered' + }, + rowspan: '1', + colspan: '1', + row: 'row-0jwjg3', + cell: 'cell-1azhl2' + } + }, + { insert: 'd' }, + { + insert: '\n', + attributes: { + 'block-id': 'block-5d73a2c7-f98b-47c7-a3f5-0d8527962b02', + list: { + rowspan: '1', + colspan: '1', + row: 'row-0jwjg3', + cell: 'cell-1azhl2', + list: 'ordered' + }, + rowspan: '1', + colspan: '1', + row: 'row-0jwjg3', + cell: 'cell-1azhl2' + } + }, + { insert: 'e' }, + { + insert: '\n', + attributes: { + 'block-id': 'block-bfda76ee-ffdd-45db-a22e-a6707e11cf68', + list: { + rowspan: '1', + colspan: '1', + row: 'row-0jwjg3', + cell: 'cell-1azhl2', + list: 'ordered' + }, + rowspan: '1', + colspan: '1', + row: 'row-0jwjg3', + cell: 'cell-1azhl2' + } + }, + { insert: 'd' }, + { + insert: '\n', + attributes: { + 'block-id': 'block-35242e64-a69d-4cdb-bd85-2a93766bfab4', + list: { + rowspan: '1', + colspan: '1', + row: 'row-0jwjg3', + cell: 'cell-1azhl2', + list: 'ordered' + }, + rowspan: '1', + colspan: '1', + row: 'row-0jwjg3', + cell: 'cell-1azhl2' + } + }, + { insert: 'f' }, + { + insert: '\n', + attributes: { + 'block-id': 'block-8baa22c8-491b-4f1b-9502-44179d5ae744', + list: { + rowspan: '1', + colspan: '1', + row: 'row-0jwjg3', + cell: 'cell-1azhl2', + list: 'ordered' + }, + rowspan: '1', + colspan: '1', + row: 'row-0jwjg3', + cell: 'cell-1azhl2' + } + }, + { + insert: '\n', + attributes: { 'block-id': 'block-7fa64af0-6974-4205-8cee-529f8bd46852' } + }, + { insert: { divider: true } }, + { insert: "Brandon's Section" }, + { + insert: '\n', + attributes: { + header: 2, + 'block-id': 'block-cf49462c-2370-48ff-969d-576cb32c39a1' + } + }, + { + insert: '\n', + attributes: { 'block-id': 'block-30ef8361-0dd6-4eee-b4eb-c9012d0e9070' } + }, + { + insert: { + slash_command: { + id: 'doc_94zq-2436', + sessionId: 'x9x08o916', + replace: '/' + } + } + }, + { + insert: '\n', + attributes: { 'block-id': 'block-166ed856-cf8c-486a-9365-f499b21d91b3' } + }, + { insert: { divider: true } }, + { + insert: '\n', + attributes: { + row: 'row-kssn15', + rowspan: '1', + colspan: '1', + 'block-id': 'block-e8079594-4559-4259-98bb-da5280e2a692', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-kssn15', + cell: 'cell-qxbksf' + }, + cell: 'cell-qxbksf' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-70132663-14cc-4701-b5c5-eb99e875e2bd', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-kssn15', + cell: 'cell-lsohbx' + }, + cell: 'cell-lsohbx', + row: 'row-kssn15', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-47a3899c-e3c5-4a7a-a8c4-46e0ae73a4fa', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-kssn15', + cell: 'cell-hner9k' + }, + cell: 'cell-hner9k', + row: 'row-kssn15', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-0f9e650a-7841-412e-b4f2-5571b6d352c2', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-juxwc0', + cell: 'cell-ei4yqp' + }, + cell: 'cell-ei4yqp', + row: 'row-juxwc0', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-53a158a9-8c82-4c82-9d4e-f5298257ca43', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-juxwc0', + cell: 'cell-25pf5x' + }, + cell: 'cell-25pf5x', + row: 'row-juxwc0', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-da8ba35e-ce6e-4518-8605-c51d781eb07a', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-juxwc0', + cell: 'cell-m8reor' + }, + cell: 'cell-m8reor', + row: 'row-juxwc0', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-2dce37c7-2978-4127-bed0-9549781babcb', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-ot4wy5', + cell: 'cell-dinh0i' + }, + cell: 'cell-dinh0i', + row: 'row-ot4wy5', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-7b593f8c-4ea3-44b4-8ad9-4a0abffe759b', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-ot4wy5', + cell: 'cell-d115b2' + }, + cell: 'cell-d115b2', + row: 'row-ot4wy5', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-272c28e6-2bde-4477-9d99-ce35b3045895', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-ot4wy5', + cell: 'cell-fuapvo' + }, + cell: 'cell-fuapvo', + row: 'row-ot4wy5', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { 'block-id': 'block-fbf23cab-1ce9-4ede-9953-f2f8250004cf' } + }, + { + insert: '\n', + attributes: { 'block-id': 'block-c3fbb8c9-495c-40b0-b0dd-f6e33dd64b1b' } + }, + { + insert: '\n', + attributes: { 'block-id': 'block-3417ad09-92a3-4a43-b5db-6dbcb0f16db4' } + }, + { + insert: '\n', + attributes: { 'block-id': 'block-b9eacdce-4ba3-4e66-8b69-3eace5656057' } + }, + { insert: 'Dan Gornstein' }, + { + insert: '\n', + attributes: { + 'block-id': 'block-d7c6ae0d-a17c-433e-85fd-5efc52b587fb', + header: 1 + } + }, + { + insert: '\n', + attributes: { 'block-id': 'block-814521bd-0e14-4fbf-b332-799c6452a624' } + }, + { insert: 'aaa' }, + { + insert: '\n', + attributes: { + 'block-id': 'block-6aaf4dcf-dc21-45c6-b723-afb25fe0f498', + list: { list: 'toggled', 'toggle-id': 'list-idl93b' } + } + }, + { insert: 'bb' }, + { + insert: '\n', + attributes: { + indent: 1, + 'block-id': 'block-3dd75392-fa50-4bfb-ba6b-3b7d6bd3f1a1', + list: { list: 'toggled', 'toggle-id': 'list-mrq7j2' } + } + }, + { insert: 'ccc' }, + { + insert: '\n', + attributes: { + 'block-id': 'block-2528578b-ecda-4f74-9fd7-8741d72dc8b3', + indent: 2, + list: { list: 'toggled', 'toggle-id': 'list-liu7dl' } + } + }, + { + insert: '\n', + attributes: { 'block-id': 'block-18bf68c3-9ef3-4874-929c-9b6bb1a00325' } + }, + { + insert: '\n', + attributes: { 'table-col': { width: '150' } } + }, + { insert: '\n', attributes: { 'table-col': { width: '150' } } }, + { + insert: '\n', + attributes: { 'table-col': { width: '150' } } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-d44e74b4-b37f-48e0-b319-6327a6295a57', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-si1nah', + cell: 'cell-cpybie' + }, + row: 'row-si1nah', + cell: 'cell-cpybie', + rowspan: '1', + colspan: '1' + } + }, + { insert: 'aaa' }, + { + insert: '\n', + attributes: { + 'block-id': 'block-3e545ee9-0c9a-42d7-a4d0-833edb8087f3', + list: { + rowspan: '1', + colspan: '1', + row: 'row-si1nah', + cell: 'cell-cpybie', + list: 'toggled', + 'toggle-id': 'list-kjl2ik' + }, + rowspan: '1', + colspan: '1', + row: 'row-si1nah', + cell: 'cell-cpybie' + } + }, + { insert: 'bb' }, + { + insert: '\n', + attributes: { + indent: 1, + 'block-id': 'block-5f1225ad-370f-46ab-8f1e-18b277b5095f', + list: { + rowspan: '1', + colspan: '1', + row: 'row-si1nah', + cell: 'cell-cpybie', + list: 'toggled', + 'toggle-id': 'list-eei1x5' + }, + rowspan: '1', + colspan: '1', + row: 'row-si1nah', + cell: 'cell-cpybie' + } + }, + { insert: 'ccc' }, + { + insert: '\n', + attributes: { + indent: 2, + 'block-id': 'block-a77fdc11-ad24-431b-9ca2-09e32db94ac2', + list: { + rowspan: '1', + colspan: '1', + row: 'row-si1nah', + cell: 'cell-cpybie', + list: 'toggled', + 'toggle-id': 'list-30us3c' + }, + rowspan: '1', + colspan: '1', + row: 'row-si1nah', + cell: 'cell-cpybie' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-d44e74b4-b37f-48e0-b319-6327a6295a57', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-si1nah', + cell: 'cell-cpybie' + }, + row: 'row-si1nah', + cell: 'cell-cpybie', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-2c274c8a-757d-4892-8db8-1a7999f7ab51', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-si1nah', + cell: 'cell-al1z64' + }, + row: 'row-si1nah', + cell: 'cell-al1z64', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-85931afe-1879-471c-bb4b-89e7bd517fe9', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-si1nah', + cell: 'cell-q186pb' + }, + row: 'row-si1nah', + cell: 'cell-q186pb', + rowspan: '1', + colspan: '1' + } + }, + { insert: 'asdfasdfasdf' }, + { + insert: '\n', + attributes: { + 'block-id': 'block-6e0522e8-c1eb-4c07-98df-2b07c533a139', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-7x2d1o', + cell: 'cell-6eid2t' + }, + row: 'row-7x2d1o', + cell: 'cell-6eid2t', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-4b3d0bd0-9175-45e9-955c-e8164f4b5376', + row: 'row-7x2d1o', + cell: 'cell-m1alad', + rowspan: '1', + colspan: '1', + list: { + rowspan: '1', + colspan: '1', + row: 'row-7x2d1o', + cell: 'cell-m1alad', + list: 'ordered' + } + } + }, + { insert: 'asdfasdfasdf' }, + { + insert: '\n', + attributes: { + 'block-id': 'block-08610089-cb05-4366-bb1e-a0787d5b11bf', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-7x2d1o', + cell: 'cell-dm1l2p' + }, + row: 'row-7x2d1o', + cell: 'cell-dm1l2p', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-c22b5125-8df3-432f-bd55-5ff456e41b4e', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-o0ujua', + cell: 'cell-82g0ca' + }, + row: 'row-o0ujua', + cell: 'cell-82g0ca', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-7c6320e4-acaf-4ab4-8355-c9b00408c9c1', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-o0ujua', + cell: 'cell-wv6ozp' + }, + row: 'row-o0ujua', + cell: 'cell-wv6ozp', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-d1bb7bed-e69e-4807-8d20-2d28fef8d08f', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-o0ujua', + cell: 'cell-ldt53x' + }, + row: 'row-o0ujua', + cell: 'cell-ldt53x', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { 'block-id': 'block-28f28cb8-51a2-4156-acf9-2380e1349745' } + }, + { insert: { divider: true } }, + { + insert: '\n', + attributes: { 'block-id': 'block-a1193252-c0c8-47fe-b9f6-32c8b01a1619' } + }, + { insert: '\n', attributes: { 'table-col': { width: '150' } } }, + { + insert: '\n\n', + attributes: { 'table-col': { width: '150' } } + }, + { insert: '/This is a test.' }, + { + insert: '\n', + attributes: { + 'block-id': 'block-14188df0-a63f-4317-9a6d-91b96a7ac9fe', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-5ixdvv', + cell: 'cell-9tgyed' + }, + row: 'row-5ixdvv', + cell: 'cell-9tgyed', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-7e5ba2af-9903-457d-adf4-2a79be81d823', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-5ixdvv', + cell: 'cell-xc56e9' + }, + row: 'row-5ixdvv', + cell: 'cell-xc56e9', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-eb6cad93-caf7-4848-8adf-415255139268', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-5ixdvv', + cell: 'cell-xrze3u' + }, + row: 'row-5ixdvv', + cell: 'cell-xrze3u', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-5bb547a2-6f71-4624-80c7-d0e1318c81a2', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-xbzv98', + cell: 'cell-lie0ng' + }, + row: 'row-xbzv98', + cell: 'cell-lie0ng', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-b506de0d-efb6-4bd7-ba8e-2186cc57903e', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-xbzv98', + cell: 'cell-s9sow1' + }, + row: 'row-xbzv98', + cell: 'cell-s9sow1', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-42d2ad20-5521-40e3-a88d-fe6906176e61', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-xbzv98', + cell: 'cell-nodtcj' + }, + row: 'row-xbzv98', + cell: 'cell-nodtcj', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-7d3e4216-3f68-4dd6-bc77-4a9fad4ba008', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-5bqfil', + cell: 'cell-c8c0f3' + }, + row: 'row-5bqfil', + cell: 'cell-c8c0f3', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-6671f221-551e-47fb-9b7d-9043b6b12cdc', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-5bqfil', + cell: 'cell-jvxxif' + }, + row: 'row-5bqfil', + cell: 'cell-jvxxif', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { + 'block-id': 'block-51e3161b-0437-4fe3-ac4f-129a93a93fc3', + 'table-cell-line': { + rowspan: '1', + colspan: '1', + row: 'row-5bqfil', + cell: 'cell-rmjpze' + }, + row: 'row-5bqfil', + cell: 'cell-rmjpze', + rowspan: '1', + colspan: '1' + } + }, + { + insert: '\n', + attributes: { 'block-id': 'block-21099df0-afb2-4cd3-834d-bb37800eb06a' } + } + ] + const ydoc = new Y.Doc() + const ytext = ydoc.getText('id') + ytext.applyDelta(initialContent) + const changeEvent = [ + { retain: 90 }, + { delete: 4 }, + { + retain: 1, + attributes: { + layout: null, + 'layout-width': null, + 'block-id': 'block-9d6566a1-be55-4e20-999a-b990bc15e143' + } + } + ] + ytext.applyDelta(changeEvent) + const delta = ytext.toDelta() + t.compare(delta[41], { + insert: '\n', + attributes: { + 'block-id': 'block-9d6566a1-be55-4e20-999a-b990bc15e143' + } + }) +} + /** * In this test we are mainly interested in the cleanup behavior and whether the resulting delta makes sense. * It is fine if the resulting delta is not minimal. But applying the delta to a rich-text editor should result in a