Ecommerce Shopify WordPress Discussion

Register one keystroke on element call

I'm building a Gutenberg block, and in my editor block I've got a text-based (p, h2...) element with contenteditable set as true, it's got a callback of onInput, when any keystroke is pressed it calls the function I've linked to it. This is working as I'd like it to but for every keypress the cursor is moved to the start of the text. I've tried to set a timer but it just means all of the keystroke functions are delayed by however long I set. I would like to be able to cut the calls down to a single call, or alternatively if there is a known way to not have the cursor position be reset whenever I update the content that would also be great. wp.blocks.registerBlockType( 'arttastic/about-block', { title: 'About Block', icon: 'info', category: 'design', attributes: { title: { type: 'string', default: 'Title' }, content: { type: 'string', default: 'content' }, img: { type: 'image' }, btn_text: { type: 'text', default: 'Button' }, btn_link: { type: 'url', default: 'https://www.amias.dev' } }, edit: function(props) { let updateAttr = ( event, attr ) => { props.setAttributes( { [attr]: event.target.innerText } ); } // return htmlEl( gutenbergEditor() ); return gutenbergEditor( props, updateAttr ); }, save: function(props) { return frontEnd( props ); } }); let gutenbergEditor = ( props, updateAttr ) => { return React.createElement( 'div', null, React.createElement( 'h2', { contenteditable: 'true', onInput: e => { setTimeout( updateAttr, 5000, e, 'title' ); } }, props.attributes.title ), React.createElement( 'p', { contenteditable: 'true', onInput: e => { updateAttr( e, 'content' ); } }, props.attributes.content ), React.createElement( 'p', { contenteditable: 'true', onInput: e => { updateAttr( e, 'button_text' ); } }, props.attributes.button_text ) ); }
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.