From 395a7850e4818cfc1a2feb6e7d27a6732b98ade0 Mon Sep 17 00:00:00 2001 From: Yanuo Ma Date: Sat, 7 Mar 2026 00:59:43 -0500 Subject: [PATCH] fix(keymaps): guard nil changes in find_hunk_at_cursor find_hunk_at_cursor() crashed with 'attempt to get length of field changes (a nil value)' when stored_diff_result existed but its .changes field was nil (e.g. after single-pane views or during async transitions). Add a nil check before accessing #diff_result.changes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- lua/codediff/ui/view/keymaps.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/codediff/ui/view/keymaps.lua b/lua/codediff/ui/view/keymaps.lua index 00c9ed85..544ca80c 100644 --- a/lua/codediff/ui/view/keymaps.lua +++ b/lua/codediff/ui/view/keymaps.lua @@ -70,7 +70,7 @@ function M.setup_all_keymaps(tabpage, original_bufnr, modified_bufnr, is_explore return nil, nil end local diff_result = session.stored_diff_result - if #diff_result.changes == 0 then + if not diff_result.changes or #diff_result.changes == 0 then return nil, nil end