How to get startIndex and endIndex from the selected block in gutenberg?

I am trying to get the start index and end index of selection from a gutenberg block.i could get the selected block by w

I am trying to get the start index and end index of selection from a gutenberg block.

i could get the selected block by

wp.data.select('core/block-editor').getSelectedBlock()

Here is the object returned by block editor

the object returned doesn't have any methods to retrieve the selection start and end in the block, the attributes property does only have the full text, is there an API method which could get this start and end index?

P.s: i could find startIndex, endIndex in props when i register a toolbar button by using this example (/), the problem i am facing is i couldn't get it externally

I am trying to get the start index and end index of selection from a gutenberg block.

i could get the selected block by

wp.data.select('core/block-editor').getSelectedBlock()

Here is the object returned by block editor

the object returned doesn't have any methods to retrieve the selection start and end in the block, the attributes property does only have the full text, is there an API method which could get this start and end index?

P.s: i could find startIndex, endIndex in props when i register a toolbar button by using this example (https://developer.wordpress/block-editor/tutorials/format-api/3-apply-format/), the problem i am facing is i couldn't get it externally

Share Improve this question asked Feb 29, 2020 at 11:08 NaveenNaveen 1273 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You can use these to get the start and end of the selection:

var startIndex = wp.data.select('core/block-editor').getSelectionStart();
var endIndex   = wp.data.select('core/block-editor').getSelectionEnd();

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742357280a4428690.html

相关推荐

  • How to get startIndex and endIndex from the selected block in gutenberg?

    I am trying to get the start index and end index of selection from a gutenberg block.i could get the selected block by w

    6小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信