As you can see, the cursor is within bold characters, so the next character would be bold too. The editor noticed it and activated the bold button on the toolbar.
How can I check the style under cursor in draft.js, just like the above one?
As you can see, the cursor is within bold characters, so the next character would be bold too. The editor noticed it and activated the bold button on the toolbar.
How can I check the style under cursor in draft.js, just like the above one?
Share Improve this question asked Feb 21, 2018 at 13:11 SeareneSearene 27.7k40 gold badges146 silver badges198 bronze badges2 Answers
Reset to default 9I just found out that I could check the style using a one-liner. It works whether there's a selection or not.
editorState.getCurrentInlineStyle().has(style);
function getInlineStylesForCollapsedSelection(editorState, selection) {
if (selection.isCollapsed() === false) {
throw new Error('Selection must be collapsed');
}
return editorState
.getCurrentContent()
.getBlockForKey(selection.getStartKey())
.getInlineStyleAt(selection.getStartOffset());
}