From 8c102cd29e074f0bdace398e0addd9953aeaddb4 Mon Sep 17 00:00:00 2001 From: Sebastian Lyng Johansen Date: Mon, 25 Aug 2025 14:56:40 +0200 Subject: [PATCH] fix: default to normal mode after applying inline diff Problem: It is annoying to always have to press `` before being able to either accept or reject the diff with `gda` or `gdr`. Solution: Default to normal mode when in applying inline diff to allow users to immediately accept/reject diffs --- lua/codecompanion/providers/diff/inline.lua | 4 ++++ tests/providers/diff/test_inline.lua | 1 + 2 files changed, 5 insertions(+) diff --git a/lua/codecompanion/providers/diff/inline.lua b/lua/codecompanion/providers/diff/inline.lua index 82d9b6a70..f322e53c2 100644 --- a/lua/codecompanion/providers/diff/inline.lua +++ b/lua/codecompanion/providers/diff/inline.lua @@ -48,6 +48,10 @@ function InlineDiff.new(args) local winnr = vim.fn.bufwinid(self.bufnr) if winnr ~= -1 then pcall(api.nvim_win_set_cursor, winnr, { first_diff_line, 0 }) + + if vim.api.nvim_get_mode().mode ~= "n" then + vim.api.nvim_input("") + end end end) end diff --git a/tests/providers/diff/test_inline.lua b/tests/providers/diff/test_inline.lua index d98e60a1f..901e4c1e9 100644 --- a/tests/providers/diff/test_inline.lua +++ b/tests/providers/diff/test_inline.lua @@ -190,6 +190,7 @@ T["InlineDiff"]["apply_diff_highlights - applies highlights for changes"] = func diff:apply_diff_highlights(old_lines, new_lines) h.expect_truthy(#diff.extmark_ids >= initial_extmarks) + h.eq(vim.api.nvim_get_mode().mode, "n") end T["InlineDiff"]["clear_highlights - removes all extmarks"] = function()