From 46932e5410c549036a6b2ee5feeb82eee5ef979a Mon Sep 17 00:00:00 2001 From: NicolasGB Date: Tue, 28 Apr 2026 17:27:31 +0200 Subject: [PATCH] feat(log/summary): Add `o` keymap from the summary that allows users to do the equivalent of `Jtabedit` of the file in under the cursor --- README.md | 1 + lua/jj/cmd/init.lua | 2 ++ lua/jj/cmd/log.lua | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/README.md b/README.md index fb6d3d2..5c08d69 100644 --- a/README.md +++ b/README.md @@ -545,6 +545,7 @@ revision via `jj diffedit`. Immutable revisions show an error on write. diff = "", -- Diff file at this revision edit = "", -- Edit revision and open file edit_immutable = "", -- Edit revision (ignore immutability) and open file + edit_file = "o", -- Open the file under cursor in a new tab like `:Jtabedit` would }, }, -- Status buffer keymaps (set to nil to disable) diff --git a/lua/jj/cmd/init.lua b/lua/jj/cmd/init.lua index 5c78b56..db10989 100644 --- a/lua/jj/cmd/init.lua +++ b/lua/jj/cmd/init.lua @@ -76,6 +76,7 @@ local split_module = require("jj.cmd.split") --- @field diff? string|string[] --- @field edit? string|string[] --- @field edit_immutable? string|string[] +--- @field edit_file? string|string[] --- @class jj.cmd.bookmark --- @field prefix? string Prefix to append when creating a bookmark @@ -185,6 +186,7 @@ M.config = { diff = "", edit = "", edit_immutable = "", + edit_file = "o", }, split = "", tag_set = "", diff --git a/lua/jj/cmd/log.lua b/lua/jj/cmd/log.lua index 70b723e..74903e1 100644 --- a/lua/jj/cmd/log.lua +++ b/lua/jj/cmd/log.lua @@ -938,6 +938,25 @@ function M.handle_summary_edit(revset, ignore_immut) end, string.format("Error editing revset: `%s`", revset)) end +--- Handle edit action in summary tooltip but only for the file (like Jedit) +--- Closes tooltip, edits the revision, and opens the file +--- @param revset string The revision to edit +function M.handle_summary_file_edit(revset) + local line = vim.api.nvim_get_current_line() + local filepath = parser.parse_file_info_from_status_line(line) + if not filepath then + utils.notify("No file found on this line", vim.log.levels.WARN) + return + end + + -- Close the tooltip first + if terminal.state.tooltip_buf and vim.api.nvim_buf_is_valid(terminal.state.tooltip_buf) then + terminal.close_tooltip() + end + + require("jj.file").open_target({ path = filepath.new_path, rev = revset, split = "tab" }) +end + --- Get keymaps for summary tooltip --- @param revset string The revision being viewed --- @return jj.core.buffer.keymap[] @@ -963,6 +982,12 @@ function M.summary_keymaps(revset) args = { revset, true }, opts = { desc = "Edit revision (ignore immutability) and open file" }, }, + edit_file = { + modes = { "n" }, + handler = M.handle_summary_file_edit, + args = { revset, true }, + opts = { desc = "Read revision in buffer like `Jedit`" }, + }, } return cmd.resolve_keymaps_from_specs(keymaps, specs) end