This repository was archived by the owner on Feb 6, 2023. It is now read-only.
Commit c21a9f7
Fix bad destructuring when content block key has a
Summary:
**Summary**
If a content block was created with a key that contains the `-`, it would fail to decode the `decoratorKey` and the `leafKey` because the current implementation relies on `-` to be a parsing delimiter. Here's an example:
```js
class SomeComponent extends React.Component {
constructor(props) {
super(props);
const block = new ContentBlock({
type: 'paragraph',
text: 'some-text',
key: 'some-key'
});
const contentState = ContentBlock.createFromBlockArray([block]);
this.state = {editorState: EditorState.createWithContent(contentState)};
this.onChange = editorState => this.setState({editorState});
}
render() {
return (
<Editor
editorState={this.state.editorState}
onChange={this.onChange}
/>
);
}
}
```
When you select anywhere on the editor, you'd get this error:
```
TypeError: Cannot read property 'getIn' of undefined
45 | const focusBlockKey = focusPath.blockKey;
46 | const focusLeaf = editorState
> 47 | .getBlockTree(focusBlockKey)
| ^
48 | .getIn([focusPath.decoratorKey, 'leaves', focusPath.leafKey]);
49 |
50 | const anchorLeafStart: number = anchorLeaf.get('start');
at getUpdatedSelectionState (src/component/selection/getUpdatedSelectionState.js:47:30)
at getDraftEditorSelectionWithNodes (src/component/selection/getDraftEditorSelectionWithNodes.js:48:58)
at getDraftEditorSelection (src/component/selection/getDraftEditorSelection.js:37:53)
at assertGetDraftEditorSelection (src/component/selection/__tests__/getDraftEditorSelection-test.js:55:53)
at Object.<anonymous> (src/component/selection/__tests__/getDraftEditorSelection-test.js:211:3)
```
**Test Plan**
Added a unit test for `DraftOffsetKey.js` to check for all delimiter cases.
Pull Request resolved: #1995
Differential Revision: D13982004
fbshipit-source-id: 3cd5967ad86041e310c41e7bcbfff4e868062804- (#1995)1 parent a97ed7e commit c21a9f7
File tree
3 files changed
+70
-2
lines changed- src/component/selection
- __tests__
- __snapshots__
3 files changed
+70
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
29 | 33 | | |
30 | | - | |
| 34 | + | |
| 35 | + | |
31 | 36 | | |
32 | 37 | | |
33 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
Lines changed: 33 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
0 commit comments