admin管理员组

文章数量:1323200

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 badges
Add a ment  | 

2 Answers 2

Reset to default 9

I 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());
}

本文标签: javascriptIs there any way to get the style under cusor in draftjsStack Overflow