fix: guard setCursor against nil and fallback getNextCol on regex miss#2
Open
vann-at-cpcp-dot-tw wants to merge 1 commit into
Open
fix: guard setCursor against nil and fallback getNextCol on regex miss#2vann-at-cpcp-dot-tw wants to merge 1 commit into
vann-at-cpcp-dot-tw wants to merge 1 commit into
Conversation
When editing text containing certain multi-byte or edge-case characters,
pressing insert-mode motion keys (e.g. Right arrow) could crash with:
E5108: attempt to perform arithmetic on local 'col' (a nil value)
at setCursor (core.lua:94)
called from rmbMotionRight.move (core.lua:533)
Root cause:
- getNextCol uses vim.regex("\\%Xc.") which can miss in edge cases,
returning `nil` via `return to and to + 1`.
- setCursor then does `col - 1` on nil and throws.
Fix:
1. setCursor: early-return when row/col is nil (defense-in-depth,
covers all motion paths that pass nil through).
2. getNextCol: fallback to the naive `col + 1` on regex miss
(matches the author's own commented-out `col_target = col + 1`
intent at rmbMotionRight, keeps cursor moving instead of no-op).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a crash in insert-mode motions when the cursor is near certain multi-byte / edge-case characters.
Reproduction
Open a markdown file, paste text containing CJK or special characters, then press
<Right>/<Left>in insert mode. Get:```
E5108: Error executing lua: ...lua/rambo/core.lua:94: attempt to perform arithmetic on local 'col' (a nil value)
stack traceback:
...lua/rambo/core.lua:94: in function 'setCursor'
...lua/rambo/core.lua:533: in function 'move'
...lua/rambo/core.lua:1169: in function <...>
```
Root cause
`getNextCol` uses `vim.regex("\\%Xc.")` which can miss at edge byte positions, returning `nil` via `return to and to + 1`. `setCursor` then does `col - 1` on nil → crash.
Fix
`getPrevCol` returning `nil` at line-start is left alone — it's a meaningful boundary; the `setCursor` guard makes it safe.
Test plan
🤖 Generated with Claude Code