From a6e163bcc3a6b75e5b6d4190b64ed4b39f8ddb0c Mon Sep 17 00:00:00 2001 From: Naoki Mizuno Date: Thu, 19 Mar 2026 19:06:53 +0900 Subject: [PATCH] feat(log/keymap): add keymaps to move on revision in log buffer (#100) --- README.md | 2 ++ lua/jj/cmd/init.lua | 2 ++ lua/jj/cmd/log.lua | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/README.md b/README.md index 3904fbb..f019162 100644 --- a/README.md +++ b/README.md @@ -514,6 +514,8 @@ The plugin also provides `:Jdiff`, `:Jvdiff`, and `:Jhdiff` commands for diffing change_revset = "", -- Change the revset(s) being viewed in the log buffer tag_set = "", -- Create a tag on the revision under cursor summary = "", -- Show summary tooltip for revision under cursor + select_next_revision = "gj", -- Move cursor to the next revision in the log + select_prev_revision = "gk", -- Move cursor to the previous revision in the log summary_tooltip = { diff = "", -- Diff file at this revision edit = "", -- Edit revision and open file diff --git a/lua/jj/cmd/init.lua b/lua/jj/cmd/init.lua index 5b71af6..b1bdf69 100644 --- a/lua/jj/cmd/init.lua +++ b/lua/jj/cmd/init.lua @@ -201,6 +201,8 @@ M.config = { tag_set = "", history = "", change_revset = "", + select_next_revision = "gj", + select_prev_revision = "gk", }, status = { open_file = "", diff --git a/lua/jj/cmd/log.lua b/lua/jj/cmd/log.lua index b4e9b6f..1c0c820 100644 --- a/lua/jj/cmd/log.lua +++ b/lua/jj/cmd/log.lua @@ -1023,6 +1023,37 @@ function M.handle_log_summary() end end +--- Move cursor to the next or previous revision line in the log buffer. +--- @param direction integer 1 for next, -1 for previous +local function select_revision(direction) + local buf = terminal.state.buf or vim.api.nvim_get_current_buf() + local total_lines = vim.api.nvim_buf_line_count(buf) + + -- Start scanning from the line after/before the current revision line + local revset_line, _ = get_revset_line() + local start = revset_line + 1 + direction -- revset_line is 0-indexed; convert to 1-indexed then step + + local line = start + while line >= 1 and line <= total_lines do + local content = vim.api.nvim_buf_get_lines(buf, line - 1, line, false)[1] + if parser.get_revset(content) then + buffer.set_cursor(buf, { line, 0 }) + return + end + line = line + direction + end +end + +--- Move cursor to the next revision in the log buffer +function M.handle_log_select_next_revision() + select_revision(1) +end + +--- Move cursor to the previous revision in the log buffer +function M.handle_log_select_prev_revision() + select_revision(-1) +end + --- Resolve log keymaps from config, filtering out nil values --- @return jj.core.buffer.keymap[] function M.log_keymaps() @@ -1166,6 +1197,16 @@ function M.log_keymaps() desc = "Change the revset(s) being viewed", handler = M.handle_log_change_revset, modes = { "n", "v" }, + }, + select_next_revision = { + desc = "Move cursor to the next revision", + handler = M.handle_log_select_next_revision, + modes = { "n", "v" }, + }, + select_prev_revision = { + desc = "Move cursor to the previous revision", + handler = M.handle_log_select_prev_revision, + modes = { "n", "v" }, }, }