Restoring previous selection
See original GitHub issueFrikken loving this project!!
I have an auto save pipeline which will then result in a redux auto prop pass in, which then causes a rerender. This works okay from a content standpoint as it is simply reloading the content I just saved, however I am having problems with restoring the selection state.
At the moment I track all changes via the onChange
event. Then when I receive the “persisted” state back from redux I want to try and restore the selection using the existing state that is currently on the component, but I can’t seem to get this to work.
Here is my current attempt:
// The state from props/redux.
const editorState = Raw.deserialize(this.props.editorState);
// Any existing tracked state.
const { editorState: existingEditorState } = this.state;
let selectionProps;
if (!!existingEditorState) {
selectionProps = {
anchorKey: existingEditorState.anchorKey,
anchorOffset: existingEditorState.anchorOffset,
focusKey: existingEditorState.focusKey,
focusOffset: existingEditorState.focusOffset,
isFocused: existingEditorState.isFocused,
isBackward: existingEditorState.isBackward
};
}
this.setState({
editorState: !!props
// Try re-set the existing selection.
? editorState.transform().moveTo(selectionProps).apply()
// First time render, use as is.
: editorState
});
Any ideas? Have I completely misunderstood the API docs? 😃
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Restoring Selections - Photoshop Training Channel
If you want to restore the last selection used, press Ctrl Shift D (Mac: Command Shift D). This is a very handy shortcut...
Read more >Restore a previous version of a file without unwanted changes
Open the file you want to restore and go to File > Info. If the file has previous versions, you'll see a button...
Read more >How to Restore a File or Folder to a Previous Version [Windows]
Right-click the file or folder, then click Show more options. Click Restore previous versions. Select the version you want to restore, then ...
Read more >How to Restore Previous Versions of Files in Windows 10
Right-click the file or folder, then select the Restore previous versions option.
Read more >How to enable Previous Versions to recover files on Windows 10
To enable restore point to recover lost or delete files with previous versions, use these steps: ... Click the Configure button. ... Select...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yup, that’s right. The keys are randomly generated whenever you serialize/deserialize an
State
right now, so the selection won’t find the same nodes anymore. It seems like the better way to go would be to have the editor not need to re-load the identical state, since this would result in a lot of extra re-rendering since the immutable objects would also all be re-created.Going to close for now, glad that helped!