Skip to content

Instantly share code, notes, and snippets.

@Katerina198b
Last active May 2, 2020 11:49
Show Gist options
  • Save Katerina198b/8fe6a69c1a39834b80d18ee9cf94ebef to your computer and use it in GitHub Desktop.
Save Katerina198b/8fe6a69c1a39834b80d18ee9cf94ebef to your computer and use it in GitHub Desktop.
function getCurrentBlock(editorState) {
const currentSelection = editorState.getSelection();
const blockKey = currentSelection.getStartKey();
return(editorState.getCurrentContent().getBlockForKey(blockKey));
}
function getCurrentLetter(editorState) {
const currentBlock = getCurrentBlock(editorState);
const blockText = currentBlock.getText();
return blockText[editorState.getSelection().getStartOffset() - 1];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment