Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lua/claude-code/keymaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,21 @@ function M.setup_terminal_navigation(claude_code, config)
end

-- Add scrolling keymaps
-- These leave terminal mode on purpose: re-entering it (e.g. with a trailing `i`)
-- jumps the view back to the terminal cursor and undoes the scroll. Press `i` to resume.
if config.keymaps.scrolling then
vim.api.nvim_buf_set_keymap(
buf,
't',
'<C-f>',
[[<C-\><C-n><C-f>i]],
[[<C-\><C-n><C-f>]],
{ noremap = true, silent = true, desc = 'Scroll full page down' }
)
vim.api.nvim_buf_set_keymap(
buf,
't',
'<C-b>',
[[<C-\><C-n><C-b>i]],
[[<C-\><C-n><C-b>]],
{ noremap = true, silent = true, desc = 'Scroll full page up' }
)
end
Expand Down
40 changes: 40 additions & 0 deletions tests/spec/keymaps_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,45 @@ describe('keymaps', function()

assert.is_false(window_navigation_found, "Window navigation keybindings should not be registered when disabled")
end)

it('should leave terminal mode after scrolling so the scroll is kept', function()
-- Setup claude_code table with an active instance buffer
claude_code.claude_code = { current_instance = 'test', instances = { test = 42 } }

config.keymaps.window_navigation = false
config.keymaps.scrolling = true

-- Reset mapped_keys
mapped_keys = {}

-- Mock buf_set_keymap
_G.vim.api.nvim_buf_set_keymap = function(bufnr, mode, lhs, rhs, opts)
table.insert(mapped_keys, {
bufnr = bufnr,
mode = mode,
lhs = lhs,
rhs = rhs,
opts = opts
})
end

-- Mock buf_is_valid
_G.vim.api.nvim_buf_is_valid = function(bufnr)
return bufnr == 42
end

keymaps.setup_terminal_navigation(claude_code, config)

local scroll_rhs = {}
for _, mapping in ipairs(mapped_keys) do
if mapping.mode == 't' and (mapping.lhs == '<C-f>' or mapping.lhs == '<C-b>') then
scroll_rhs[mapping.lhs] = mapping.rhs
end
end

-- Re-entering terminal mode would snap the view back to the cursor
assert.are.equal([[<C-\><C-n><C-f>]], scroll_rhs['<C-f>'])
assert.are.equal([[<C-\><C-n><C-b>]], scroll_rhs['<C-b>'])
end)
end)
end)