Skip to content

fix: prevent double on_choice invocation in picker - #28

Open
KEY60228 wants to merge 1 commit into
mainfrom
fix/picker-double-callback
Open

fix: prevent double on_choice invocation in picker#28
KEY60228 wants to merge 1 commit into
mainfrom
fix/picker-double-callback

Conversation

@KEY60228

Copy link
Copy Markdown
Owner

Summary

Closing the picker window fires BufLeave, whose scheduled cancel ran even after a confirm had already closed the picker — so on_choice was invoked twice: first with nil, then with the selected item. All current callers happen to nil-guard, so no visible breakage yet, but this violates the vim.ui.select-style contract the picker advertises and becomes a real bug the moment a caller does cleanup on the nil path.

Guards cancel() with the existing closed flag so only the path that actually closes the picker reports a result.

Test plan

Headless-nvim test against the real picker module, all three paths now invoke on_choice exactly once:

  • confirm via <CR>[itemA] (was [nil, itemA] before the fix)
  • cancel via q[nil]
  • cancel by leaving the window (BufLeave path) → [nil]

🤖 Generated with Claude Code

Closing the picker window fires BufLeave, whose scheduled cancel ran
even after a confirm had already closed the picker — so on_choice was
invoked twice: first with nil, then with the selected item. All current
callers happen to nil-guard, but this violates the vim.ui.select-style
contract the picker advertises.

Guard cancel() with the closed flag so only the path that actually
closes the picker reports a result.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant