Fix cursor relocation when inside removed text#3977
Fix cursor relocation when inside removed text#3977masmu wants to merge 2 commits intomicro-editor:masterfrom
Conversation
- Basic insert/remove/replace operations - Trailing whitespace updates
Previously, if a cursor was positioned strictly inside a range of text being removed (start < cursor < end), the event handler failed to update its position. This resulted in the cursor retaining its old X/Y coordinates, effectively "jumping" forward into subsequent text. The fix ensures that any cursor inside the removed region is clamped to the start of the deletion. Also adds regression tests covering: - Multiple cursors inside removed regions - Cursors spanning across removal boundaries - Multiline replacements
|
Similar bugs exist for |
|
Thanks for the review. You are correct that However, the primary goal of this PR was to fix the cursor desync issues causing annoying cursor jumps. Fixing |
|
That's fair. I pointed it out because that's the issue I first assumed this PR was fixing, and I was surprised to see no change in behavior when I went to test it. |
|
No worries, that makes sense. Would you be able to review this PR? I was hoping to get this merged soon, as this fix is a prerequisite for some more bug fixes I have already prepared. |
|
I had no time to do the review yet, but absolutely great to see an official test for this! 👍 |
This PR fixes a bug in the buffer event handler where cursors positioned strictly inside a removed text range (start < cursor < end) were not correctly updated.
Previously, the
DoTextEventlogic forTextEventRemovehandled cursors after the removed range and cursors at the end of the range, but fell through for cursors residing inside the range. This caused such cursors to retain their original (x, y) coordinates. Since the text before them was deleted, retaining the old coordinates meant the cursor effectively "jumped" forward relative to the content.Reproduction:
Without the Lua plugin system, it is difficult to trigger the bug, but it can be easily reproduced with the following code: