admin管理员组文章数量:1334133
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 badges1 Answer
Reset to default 1You 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();
本文标签: How to get startIndex and endIndex from the selected block in gutenberg
版权声明:本文标题:How to get startIndex and endIndex from the selected block in gutenberg? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742357279a2459666.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论