Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
Simplify a bit the select flushing
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiuichim committed Oct 6, 2020
1 parent a715f7c commit 54ca049
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions src/editor/SlateEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,6 @@ class SlateEditor extends Component {
}
}

/**
* This method exists because using directly the ReactEditor.focus method
* produces the issue: Enter key press in title block does not focus the newly
* created Slate Text block.
*/
focusEditorAsync = () => {
return Promise.resolve().then(() => {
ReactEditor.focus(this.state.editor);
});
};

componentDidMount() {
// watch the dom change
window.document.addEventListener(
Expand All @@ -112,7 +101,7 @@ class SlateEditor extends Component {

if (this.props.selected) {
if (!ReactEditor.isFocused(this.state.editor)) {
this.focusEditorAsync();
setTimeout(() => ReactEditor.focus(this.state.editor), 10); // flush
}
}
}
Expand All @@ -132,9 +121,7 @@ class SlateEditor extends Component {

if (!prevProps.selected && this.props.selected) {
if (!ReactEditor.isFocused(this.state.editor)) {
// TODO: should we use this.focusEditorAsync here too instead of the
// following line?
ReactEditor.focus(this.state.editor);
setTimeout(() => ReactEditor.focus(this.state.editor), 10); // flush
}
}

Expand Down

0 comments on commit 54ca049

Please sign in to comment.