Skip to content

fix(editor): selection crashes on empty buffer (A6, A7)#29

Merged
dsent merged 2 commits into
aldum:devfrom
Vadim1987:Vadim1987/fix-editor-selection-crashes
Jun 30, 2026
Merged

fix(editor): selection crashes on empty buffer (A6, A7)#29
dsent merged 2 commits into
aldum:devfrom
Vadim1987:Vadim1987/fix-editor-selection-crashes

Conversation

@Vadim1987

Copy link
Copy Markdown

A6: Search never initialized selection in its constructor, so opening search on an empty buffer and pressing up/down did arithmetic on nil. Initialize selection = 1. A7: BufferModel:set_selection took any value unchecked and restore_state feeds a saved selection unconditionally, so a stale selection on an emptied buffer indexed nil via content:last(). Clamp selection to the buffer range, and guard last() for empty content.

@dsent
dsent requested a review from hleb-rubanau June 30, 2026 02:39

@hleb-rubanau hleb-rubanau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks sane to me. I'd recommend to add a small test (so that problem won't get back unnoticed if someone alters the code), but lack of such test does not block the fix itself.

@dsent
dsent merged commit 14c1806 into aldum:dev Jun 30, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants