0

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

enter image description here

i could get the selected block by

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

Here is the object returned by block editor

enter image description here

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.org/block-editor/tutorials/format-api/3-apply-format/), the problem i am facing is i couldn't get it externally

1 Answer 1

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();
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.