Вообщем, получилось вот так:
const getSelectedText = () => {
const { getSelectedBlock, getSelectionStart, getSelectionEnd } = select('core/block-editor');
const block = getSelectedBlock();
if (!block || block.name !== 'core/paragraph') return '';
const start = getSelectionStart();
const end = getSelectionEnd();
if (!start || !end) return '';
const value = create({ html: block.attributes.content });
const sliced = slice(value, start.offset, end.offset);
return getTextContent(sliced);
};
ИИ подсказал