question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Restoring previous selection

See original GitHub issue

Frikken 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:closed
  • Created 7 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ianstormtaylorcommented, Jul 20, 2016

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.

0reactions
ianstormtaylorcommented, Jul 20, 2016

Going to close for now, glad that helped!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found