diff --git a/README.md b/README.md
index b83e7dc..6aedfc4 100644
--- a/README.md
+++ b/README.md
@@ -107,6 +107,7 @@ _See [config.lua#L9](./lua/avante/config.lua) for the full config_
ours = "co",
theirs = "ct",
both = "cb",
+ cursor = "cc",
next = "]x",
prev = "[x",
},
@@ -203,6 +204,7 @@ The following key bindings are available for use with `avante.nvim`:
| co | choose ours |
| ct | choose theirs |
| cb | choose both |
+| cc | choose cursor |
| c0 | choose none |
| ]x | move to previous conflict |
| [x | move to next conflict |
diff --git a/lua/avante/config.lua b/lua/avante/config.lua
index 4db267e..673acc2 100644
--- a/lua/avante/config.lua
+++ b/lua/avante/config.lua
@@ -97,6 +97,7 @@ M.defaults = {
theirs = "ct",
none = "c0",
both = "cb",
+ cursor = "cc",
next = "]x",
prev = "[x",
},
diff --git a/lua/avante/diff.lua b/lua/avante/diff.lua
index c3af7bc..dfd5347 100644
--- a/lua/avante/diff.lua
+++ b/lua/avante/diff.lua
@@ -26,7 +26,7 @@ local map = vim.keymap.set
-- Types
-----------------------------------------------------------------------------//
----@alias ConflictSide "'ours'"|"'theirs'"|"'both'"|"'base'"|"'none'"
+---@alias ConflictSide "'ours'"|"'theirs'"|"'both'"|"'cursor'"|"'base'"|"'none'"
--- @class AvanteConflictHighlights
--- @field current string
@@ -70,6 +70,7 @@ local SIDES = {
BOTH = "both",
BASE = "base",
NONE = "none",
+ CURSOR = "cursor",
}
-- A mapping between the internal names and the display names
@@ -79,6 +80,7 @@ local name_map = {
base = "ancestor",
both = "both",
none = "none",
+ cursor = "cursor",
}
local CURRENT_HL = "AvanteConflictCurrent"
@@ -329,10 +331,11 @@ local function register_cursor_move_events(bufnr)
end
local hint = string.format(
- "[<%s> for OURS, <%s> for THEIRS, <%s> for BOTH, <%s> for PREV, <%s> for NEXT]",
+ "[<%s> for OURS, <%s> for THEIRS, <%s> for BOTH, <%s> for CURSOR, <%s> for PREV, <%s> for NEXT]",
Config.diff.mappings.ours,
Config.diff.mappings.theirs,
Config.diff.mappings.both,
+ Config.diff.mappings.cursor,
Config.diff.mappings.prev,
Config.diff.mappings.next
)
@@ -424,6 +427,9 @@ local function set_commands()
command("AvanteConflictChooseBoth", function()
M.choose("both")
end, { nargs = 0 })
+ command("AvanteConflictChooseCursor", function()
+ M.choose("cursor")
+ end, { nargs = 0 })
command("AvanteConflictChooseBase", function()
M.choose("base")
end, { nargs = 0 })
@@ -451,6 +457,7 @@ local function set_plug_mappings()
map({ "n", "v" }, "(git-conflict-both)", "AvanteConflictChooseBoth", opts("Choose Both"))
map({ "n", "v" }, "(git-conflict-none)", "AvanteConflictChooseNone", opts("Choose None"))
map({ "n", "v" }, "(git-conflict-theirs)", "AvanteConflictChooseTheirs", opts("Choose Theirs"))
+ map("n", "(git-conflict-cursor)", "AvanteConflictChooseCursor", opts("Choose Cursor"))
map("n", "(git-conflict-next-conflict)", "AvanteConflictNextConflict", opts("Next Conflict"))
map("n", "(git-conflict-prev-conflict)", "AvanteConflictPrevConflict", opts("Previous Conflict"))
end
@@ -467,6 +474,7 @@ local function setup_buffer_mappings(bufnr)
map({ "n", "v" }, Config.diff.mappings.none, "(git-conflict-none)", opts("Choose None"))
map({ "n", "v" }, Config.diff.mappings.theirs, "(git-conflict-theirs)", opts("Choose Theirs"))
map({ "v", "v" }, Config.diff.mappings.ours, "(git-conflict-ours)", opts("Choose Ours"))
+ map("n", Config.diff.mappings.cursor, "(git-conflict-cursor)", opts("Choose Cursor"))
-- map('V', Config.diff.mappings.ours, '(git-conflict-ours)', opts('Choose Ours'))
map("n", Config.diff.mappings.prev, "(git-conflict-prev-conflict)", opts("Previous Conflict"))
map("n", Config.diff.mappings.next, "(git-conflict-next-conflict)", opts("Next Conflict"))
@@ -681,6 +689,19 @@ function M.choose(side)
lines = vim.list_extend(first, second)
elseif side == SIDES.NONE then
lines = {}
+ elseif side == SIDES.CURSOR then
+ local cursor_line = Utils.get_cursor_pos()
+ for _, pos in ipairs({ SIDES.OURS, SIDES.THEIRS, SIDES.BASE }) do
+ local data = position[name_map[pos]] or {}
+ if data.range_start and data.range_start + 1 <= cursor_line and data.range_end + 1 >= cursor_line then
+ side = pos
+ lines = Utils.get_buf_lines(data.content_start, data.content_end + 1)
+ break
+ end
+ end
+ if side == SIDES.CURSOR then
+ return
+ end
else
return
end