feat(picker): Fallback to vim.ui.select in all pickers (#126)

This commit is contained in:
Nicolas GB
2026-06-18 20:08:58 +02:00
committed by GitHub
parent af14ce8eda
commit 30d740024d
2 changed files with 42 additions and 4 deletions
+12 -2
View File
@@ -86,8 +86,8 @@
- `:Jdiff [revision]` - Vertical split diff against a jj revision
- `:Jhdiff [revision]` - Horizontal split diff
- Picker for [Snacks.nvim](https://github.com/folke/snacks.nvim)
- `picker.status()` displays the current changed files with live diff preview
- `picker.file_history()` displays the current buffer's revision history and lets you edit the selected change
- `picker.status()` displays the current changed files with live diff preview (or falls back to `vim.ui.select()`)
- `picker.file_history()` displays the current buffer's revision history and lets you edit the selected change (or falls back to `vim.ui.select()`)
- `picker.conflict()` lists conflicted revisions, previews their changes, and launches conflict resolution (with Snacks, or `vim.ui.select()` as a fallback)
## Enhanced integrations
@@ -384,6 +384,16 @@ When using the [Snacks.nvim](https://github.com/folke/snacks.nvim) picker integr
- `<Enter>` - Open the selected file
- `<C-d>` - Open the selected file and run `Jdiff`
If Snacks is not enabled, `picker.status()` falls back to `vim.ui.select()`, where selecting an entry simply opens the chosen file.
### File history picker (Snacks.nvim)
`picker.file_history()` shows the current buffer's revision history.
When Snacks is enabled, you get a fuzzy picker with a diff preview for each revision. Selecting an entry edits that revision with `jj edit <rev> --ignore-immutable` and refreshes changed buffers.
If Snacks is not enabled, `picker.file_history()` falls back to `vim.ui.select()` with the same revision list. Selecting an entry performs the same edit action and buffer refresh, but without the Snacks preview UI.
### Conflict picker (Snacks.nvim)
`picker.conflict()` opens a picker for `jj log -r 'conflicts()'`, so you can resolve conflicted revisions without first navigating to them in the log buffer.
+30 -2
View File
@@ -147,7 +147,16 @@ function M.status()
if M.config.snacks then
require("jj.picker.snacks").status(M.config, files)
else
return utils.notify("No `Picker` enabled", vim.log.levels.INFO)
vim.ui.select(files, {
prompt = "Select changed file",
format_item = function(item)
return string.format("%s %s", item.status or "", item.text or item.file or "")
end,
}, function(item)
if item and item.file then
vim.cmd("edit " .. vim.fn.fnameescape(item.file))
end
end)
end
end
@@ -230,7 +239,26 @@ function M.file_history()
if M.config.snacks then
require("jj.picker.snacks").file_log_history(M.config, log_lines)
else
return utils.notify("No `Picker` enabled", vim.log.levels.INFO)
vim.ui.select(log_lines, {
prompt = "Select revision to edit",
format_item = function(item)
return item.text or string.format("%s %s %s", item.rev or "", item.author or "", item.description or "")
end,
}, function(item)
if not item or not item.rev then
return
end
local _, ok = runner.execute_command(
string.format("jj edit %s --ignore-immutable", item.rev),
string.format("could not edit revision '%s'", item.rev)
)
if ok then
utils.reload_changed_file_buffers()
utils.notify(string.format("Editing revision `%s`", item.rev), vim.log.levels.INFO)
end
end)
end
end