diff --git a/src/model/transaction/__tests__/__snapshots__/removeRangeFromContentState-test.js.snap b/src/model/transaction/__tests__/__snapshots__/removeRangeFromContentState-test.js.snap index b53bf90019..c68271c26a 100644 --- a/src/model/transaction/__tests__/__snapshots__/removeRangeFromContentState-test.js.snap +++ b/src/model/transaction/__tests__/__snapshots__/removeRangeFromContentState-test.js.snap @@ -1,5 +1,203 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`must merge D and E when deleting range from end of D to start of E 1`] = ` +Object { + "A": Object { + "characterList": Array [ + Object { + "entity": null, + "style": Array [], + }, + Object { + "entity": null, + "style": Array [], + }, + Object { + "entity": null, + "style": Array [], + }, + Object { + "entity": null, + "style": Array [], + }, + Object { + "entity": null, + "style": Array [], + }, + ], + "children": Array [], + "data": Object {}, + "depth": 0, + "key": "A", + "nextSibling": "B", + "parent": null, + "prevSibling": null, + "text": "Alpha", + "type": "unstyled", + }, + "B": Object { + "characterList": Array [], + "children": Array [ + "C", + "F", + ], + "data": Object {}, + "depth": 0, + "key": "B", + "nextSibling": "G", + "parent": null, + "prevSibling": "A", + "text": "", + "type": "unstyled", + }, + "C": Object { + "characterList": Array [], + "children": Array [ + "D", + ], + "data": Object {}, + "depth": 0, + "key": "C", + "nextSibling": "F", + "parent": "B", + "prevSibling": null, + "text": "", + "type": "unstyled", + }, + "D": Object { + "characterList": Array [ + Object { + "entity": null, + "style": Array [], + }, + Object { + "entity": null, + "style": Array [], + }, + Object { + "entity": null, + "style": Array [], + }, + Object { + "entity": null, + "style": Array [], + }, + Object { + "entity": null, + "style": Array [], + }, + Object { + "entity": null, + "style": Array [], + }, + Object { + "entity": null, + "style": Array [], + }, + Object { + "entity": null, + "style": Array [], + }, + Object { + "entity": null, + "style": Array [], + }, + Object { + "entity": null, + "style": Array [], + }, + Object { + "entity": null, + "style": Array [], + }, + Object { + "entity": null, + "style": Array [], + }, + Object { + "entity": null, + "style": Array [], + }, + ], + "children": Array [], + "data": Object {}, + "depth": 0, + "key": "D", + "nextSibling": null, + "parent": "C", + "prevSibling": null, + "text": "DeltaElephant", + "type": "unstyled", + }, + "F": Object { + "characterList": Array [ + Object { + "entity": null, + "style": Array [], + }, + Object { + "entity": null, + "style": Array [], + }, + Object { + "entity": null, + "style": Array [], + }, + Object { + "entity": null, + "style": Array [], + }, + ], + "children": Array [], + "data": Object {}, + "depth": 0, + "key": "F", + "nextSibling": null, + "parent": "B", + "prevSibling": "C", + "text": "Fire", + "type": "unstyled", + }, + "G": Object { + "characterList": Array [ + Object { + "entity": null, + "style": Array [], + }, + Object { + "entity": null, + "style": Array [], + }, + Object { + "entity": null, + "style": Array [], + }, + Object { + "entity": null, + "style": Array [], + }, + Object { + "entity": null, + "style": Array [], + }, + Object { + "entity": null, + "style": Array [], + }, + ], + "children": Array [], + "data": Object {}, + "depth": 0, + "key": "G", + "nextSibling": null, + "parent": null, + "prevSibling": "B", + "text": "Gorila", + "type": "unstyled", + }, +} +`; + exports[`must preserve B and C since E has not been removed 1`] = ` Object { "A": Object { diff --git a/src/model/transaction/__tests__/removeRangeFromContentState-test.js b/src/model/transaction/__tests__/removeRangeFromContentState-test.js index 5e3343380f..ba65085c16 100644 --- a/src/model/transaction/__tests__/removeRangeFromContentState-test.js +++ b/src/model/transaction/__tests__/removeRangeFromContentState-test.js @@ -261,3 +261,17 @@ test('must retain B since F has not been removed', () => { treeContentState, ); }); + +// Simulates having collapsed selection at start of Elephant and hitting backspace +// We expect Elephant will be merged with previous block, Delta +test('must merge D and E when deleting range from end of D to start of E', () => { + assertRemoveRangeFromContentState( + treeSelectionState.merge({ + anchorKey: 'D', + focusKey: 'E', + anchorOffset: contentBlockNodes[3].getLength(), // end of D + focusOffset: 0, // start of E + }), + treeContentState, + ); +});