mirror of
https://github.com/zoriya/jj.nvim.git
synced 2026-08-05 10:46:08 +00:00
Feat: edit mutable changes in log buffer (#30)
This commit is contained in:
@@ -38,11 +38,12 @@ Here are some cool features you can do with jj.nvim
|
||||
You can diff any change in your log history by simply pressing `d` on it's line, yeah just like that!
|
||||

|
||||
|
||||
### Edit mutable changes
|
||||
### Edit changes
|
||||
|
||||
Jumping up and down your log history ?
|
||||
|
||||
In your log ouptut press `CR` in a line to directly edit a `mutable` change.
|
||||
If you are sure what your are doing press `S-CR` (Shift Enter) to edit a `immutable` change.
|
||||

|
||||
|
||||
### Create new changes from the log buffer
|
||||
|
||||
+35
-17
@@ -152,24 +152,39 @@ local function get_rev_from_log_line(line)
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Handle keypress enter on `jj log` buffer to edit a previous revision
|
||||
local function handle_log_enter()
|
||||
--- Handle keypress enter on `jj log` buffer to edit a revision.
|
||||
--- If ignore_immut is true, adds --ignore-immutable to the command.
|
||||
--- Silently returns if no revision is found or the jj command fails.
|
||||
--- On success, notifies and refreshes the log buffer.
|
||||
--- @param ignore_immut? boolean Pass --ignore-immutable to jj edit when true.
|
||||
local function handle_log_enter(ignore_immut)
|
||||
local line = vim.api.nvim_get_current_line()
|
||||
|
||||
local revset = get_rev_from_log_line(line)
|
||||
if not revset or revset == "" then
|
||||
return
|
||||
end
|
||||
-- If we found a revision, edit it.
|
||||
|
||||
if revset then
|
||||
-- If we found a revision, edit it
|
||||
local cmd = string.format("jj edit %s", revset)
|
||||
local _, success = utils.execute_command(cmd, "Error editing change")
|
||||
if not success then
|
||||
return
|
||||
end
|
||||
-- Build command parts.
|
||||
local cmd_parts = { "jj", "edit" }
|
||||
if ignore_immut then
|
||||
table.insert(cmd_parts, "--ignore-immutable")
|
||||
end
|
||||
|
||||
utils.notify(string.format("Editing change: `%s`", revset), vim.log.levels.INFO)
|
||||
-- Close the terminal buffer
|
||||
close_terminal_buffer()
|
||||
end
|
||||
table.insert(cmd_parts, revset)
|
||||
|
||||
-- Build cmd string
|
||||
local cmd = table.concat(cmd_parts, " ")
|
||||
|
||||
-- Try to execute cmd
|
||||
local _, success = utils.execute_command(cmd, "Error editing change")
|
||||
if not success then
|
||||
return
|
||||
end
|
||||
|
||||
utils.notify(string.format("Editing change: `%s`", revset), vim.log.levels.INFO)
|
||||
-- Close the terminal buffer
|
||||
close_terminal_buffer()
|
||||
end
|
||||
|
||||
--- Create a new change relative to the revision under the cursor in a jj log buffer.
|
||||
@@ -225,8 +240,6 @@ local function handle_log_new(flag, ignore_immut)
|
||||
M.log()
|
||||
end
|
||||
|
||||
---
|
||||
---
|
||||
--- Create a floating window for terminal output
|
||||
--- @param config table Window configuration options
|
||||
--- @param enter boolean Whether to enter the window after creation
|
||||
@@ -558,7 +571,12 @@ local function run(cmd)
|
||||
register_command_keymap({ "n" }, "X", handle_status_restore, { desc = "Restore file under cursor" })
|
||||
elseif cmd_parts[2] == "log" then
|
||||
-- Edit
|
||||
register_command_keymap({ "n" }, "<CR>", handle_log_enter, { desc = "Edit change under cursor" })
|
||||
register_command_keymap({ "n" }, "<CR>", function()
|
||||
handle_log_enter(false)
|
||||
end, { desc = "Edit change under cursor" })
|
||||
register_command_keymap({ "n" }, "<S-CR>", function()
|
||||
handle_log_enter(true)
|
||||
end, { desc = "Edit change under cursor ignoring immutability" })
|
||||
-- Diff
|
||||
register_command_keymap({ "n" }, "d", handle_log_diff, { desc = "Diff change under cursor" })
|
||||
-- New
|
||||
|
||||
Reference in New Issue
Block a user