最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is there any way to get the style under cusor in draft.js? - Stack Overflow

programmeradmin3浏览0评论

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());
}
发布评论

评论列表(0)

  1. 暂无评论