From 30d740024d743fc908549e8f7e2edba0526ea4ea Mon Sep 17 00:00:00 2001 From: Nicolas GB Date: Thu, 18 Jun 2026 20:08:58 +0200 Subject: [PATCH] feat(picker): Fallback to vim.ui.select in all pickers (#126) --- README.md | 14 ++++++++++++-- lua/jj/picker.lua | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7391762..c567470 100644 --- a/README.md +++ b/README.md @@ -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 - `` - Open the selected file - `` - 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 --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. diff --git a/lua/jj/picker.lua b/lua/jj/picker.lua index 0fdefd6..aa989bb 100644 --- a/lua/jj/picker.lua +++ b/lua/jj/picker.lua @@ -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