From 9446ad8f693f23984a71bf0be0037e35f020fc3d Mon Sep 17 00:00:00 2001 From: Spiegie Date: Wed, 19 Nov 2025 16:21:37 +0100 Subject: [PATCH] Feat: edit mutable changes in log buffer (#30) --- README.md | 3 ++- lua/jj/cmd.lua | 52 +++++++++++++++++++++++++++++++++----------------- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 3d4e563..db7e6bb 100644 --- a/README.md +++ b/README.md @@ -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! ![Diff-from-log](https://github.com/NicolasGB/jj.nvim/raw/main/assets/diff-log.gif) -### 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. ![Edit-from-log](https://github.com/NicolasGB/jj.nvim/raw/main/assets/edit-log.gif) ### Create new changes from the log buffer diff --git a/lua/jj/cmd.lua b/lua/jj/cmd.lua index cda6e2d..560dba7 100644 --- a/lua/jj/cmd.lua +++ b/lua/jj/cmd.lua @@ -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" }, "", handle_log_enter, { desc = "Edit change under cursor" }) + register_command_keymap({ "n" }, "", function() + handle_log_enter(false) + end, { desc = "Edit change under cursor" }) + register_command_keymap({ "n" }, "", 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