Perform better boundary check between cursor position and region. Fixes #2