Skip to content

Instantly share code, notes, and snippets.

@efjacobson
Created February 21, 2020 22:21
Show Gist options
  • Save efjacobson/d9b9979ace5b5f7e19a51e120159b4d1 to your computer and use it in GitHub Desktop.
Save efjacobson/d9b9979ace5b5f7e19a51e120159b4d1 to your computer and use it in GitHub Desktop.
export default (editorState) => {
const contentState = editorState.getCurrentContent();
const firstBlock = contentState.getFirstBlock();
const lastBlock = contentState.getLastBlock();
const selectionState = editorState.getSelection();
const anchorKey = selectionState.getAnchorKey();
const anchorOffset = selectionState.getAnchorOffset();
const focusKey = selectionState.getFocusKey();
const focusOffset = selectionState.getFocusOffset();
let areAllBlocksSelected = false;
if (selectionState.getIsBackward()) {
areAllBlocksSelected = anchorKey === lastBlock.getKey()
&& focusKey === firstBlock.getKey()
&& focusOffset === 0
&& anchorOffset === lastBlock.getText().length;
} else {
areAllBlocksSelected = anchorKey === firstBlock.getKey()
&& focusKey === lastBlock.getKey()
&& anchorOffset === 0
&& focusOffset === lastBlock.getText().length;
}
return areAllBlocksSelected;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment