Skip to content

feat(picker_ui): add opts.on_submit hook for custom selection action#606

Merged
dmtrKovalenko merged 2 commits into
mainfrom
triage-bot/issue-605
Jun 16, 2026
Merged

feat(picker_ui): add opts.on_submit hook for custom selection action#606
dmtrKovalenko merged 2 commits into
mainfrom
triage-bot/issue-605

Conversation

@gustav-fff

Copy link
Copy Markdown
Collaborator

Closes #605

Root cause

Picker UI hardcodes :edit (or split/vsplit/tab) on selection at lua/fff/picker_ui/picker_ui.lua:498. The only extension point — select.select_window (lua/fff/conf.lua:65) — picks the target window but cannot replace the open action itself. Use-cases like "open the directory of the selected file in oil.nvim" have no hook.

Fix

Add opts.on_submit to find_files(opts). When set, it runs in place of the default open action after the picker closes. Receives the item plus a context table (action, abs path, relative path, location, query, mode). Query history tracking still runs. No behavior change when on_submit is unset.

Signature: fun(item, ctx) where ctx = { action, path, relative_path, location, query, mode }.

Steps to reproduce

Pre-fix on main: there is no way to intercept selection. After the patch:

require('fff').find_files({
  title = 'Oil',
  on_submit = function(item, ctx)
    local dir = ctx.path:match('^(.*)[/\\\\][^/\\\\]*$')
    require('oil').toggle_float(dir)
  end,
})

Expected: oil opens at the directory containing the selected file. Actual (pre-fix): the file is :edit-ed; reporter has no hook to override.

How verified

Manual review of M.select flow: on_submit runs inside the same vim.schedule after M.close(), so picker teardown completes before the callback fires (same ordering as the default :edit path). When on_submit is unset the original path is taken verbatim.

Did not run a Neovim-level e2e — flagging for maintainer to sanity-check the oil integration interactively.

Automated triage via Gustav. Honk-Honk 🪿

Allows callers to override the default :edit action when the user picks
an item, enabling integrations like opening the directory in oil.nvim.

Refs #605
Comment thread lua/fff/picker_ui/picker_ui.lua Outdated
@dmtrKovalenko

Copy link
Copy Markdown
Owner

@gustav-fff I remember there was another related issue please find it and link

@gustav-fff

Copy link
Copy Markdown
Collaborator Author

[triage-bot] DIRECTED: related issue is #247 ("API: more structure and pass callback to all provided APIs") — same theme of exposing callback hooks on the public API. This PR addresses the selection-callback slice; #247 is broader (callbacks across all APIs) and remains open.

Honk-Honk 🪿

@dmtrKovalenko dmtrKovalenko merged commit 7a8fb85 into main Jun 16, 2026
46 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.

[Suggestion]: A way to programmatically do something with the selection results from UI picker

2 participants