Skip to content

Instantly share code, notes, and snippets.

@jorgefilipecosta
Created April 22, 2019 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgefilipecosta/e199d6b3659936fc76535545b082a869 to your computer and use it in GitHub Desktop.
Save jorgefilipecosta/e199d6b3659936fc76535545b082a869 to your computer and use it in GitHub Desktop.
(() => {
const { withSelect } = wp.data;
const { Component } = wp.element;
const { compose } = wp.compose;
class HighlightT extends Component {
componentDidUpdate(prevProps) {
const { isTyping } = this.props;
if (!isTyping && prevProps.isTyping) {
wp.data.dispatch('core/annotations').__experimentalAddAnnotation({
source: 'my-annotations-plugin',
blockClientId: wp.data.select('core/editor').getBlocks()[Math.floor((Math.random() * 4))].clientId,
richTextIdentifier: 'content',
range: {
start: 0,
end: 3,
},
});
}
}
render() {
return null;
}
}
const applyWithSelect = withSelect((select) => {
console.log('eslint');
return {
isTyping: select('core/editor').isTyping(),
};
});
const Highlight = compose(
applyWithSelect,
)( HighlightT );
const { registerPlugin } = wp.plugins;
registerPlugin('highlight', {
render: Highlight,
icon: 'admin-links',
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment