Created
February 21, 2020 22:21
-
-
Save efjacobson/d9b9979ace5b5f7e19a51e120159b4d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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