Select atomic decoration before delete

Hello!
I have created a block decoration that is treated as atomic.
This means that if I press delete from in front of it or backspace from after it, it is deleted immediately.

This is a great start but it feels unexpected for the user as it’s a big block.

Is there a way to capture the first delete or backspace press before it gets deleted, so that I can cancel that action and visually change the decoration to look selected? Then the user can press delete/backspace again to delete it.

Thanks in advance!

I think the best way to do this would be to create custom key bindings for backspace/delete, bound with a higher precedence than the default commands for those keys. In there, you’d check whether the relevant situation applies, return false if not, and if it does, select the block and return true.

1 Like

Thank you!
I’ll check back and update here once I get the chance to try this.