Decorations.replace({}) and cursor motion

I use Decorations.replace({}) to hide some text, like ‘###123###’, I set to hide range 2 to 4, the ‘#1’ will be hidden.
the text is hidden as expected.But when I move the cursor through the keyboard directional keys, the cursor will still pass through the hidden area.
even if I use atomicRange,the cursor will jump twice between ‘#’ and 2.
By using the mouse to locate the cursor, sometimes it is located at index 2, and sometimes it is located at index 3.
What should I do to solve this problem?

atomicRanges will treat the given range as a unit, so the cursor cannot move inside it. But you’ll still be able to put the cursor both before and after it. If you don’t want that, you’d have to give it a range that also covers the position (before or after) you don’t want the cursor to appear on. Or use a custom transaction filter instead to move the cursor when it falls inside of the range.

Are you sure you don’t mean 4 instead of 3? It shouldn’t be possible to put the cursor inside a replaced range with the mouse (and if I try to reproduce this, I cannot).

Thanks for your reply, It was very helpful. And It is indeed 4, not 3, I described it incorrectly.