mirror of
https://github.com/zoriya/jj.nvim.git
synced 2026-08-05 10:46:08 +00:00
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
This commit is contained in:
@@ -545,6 +545,7 @@ revision via `jj diffedit`. Immutable revisions show an error on write.
|
||||
diff = "<S-d>", -- Diff file at this revision
|
||||
edit = "<CR>", -- Edit revision and open file
|
||||
edit_immutable = "<S-CR>", -- 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)
|
||||
|
||||
@@ -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 = "<S-d>",
|
||||
edit = "<CR>",
|
||||
edit_immutable = "<S-CR>",
|
||||
edit_file = "o",
|
||||
},
|
||||
split = "<C-s>",
|
||||
tag_set = "<S-t>",
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user