feat: pick conflict under cursor (#355)
Added `cc` which picks the conflict under the cursor, if there is one.
This commit is contained in:
parent
5c1861d93f
commit
abe08d5283
@ -107,6 +107,7 @@ _See [config.lua#L9](./lua/avante/config.lua) for the full config_
|
|||||||
ours = "co",
|
ours = "co",
|
||||||
theirs = "ct",
|
theirs = "ct",
|
||||||
both = "cb",
|
both = "cb",
|
||||||
|
cursor = "cc",
|
||||||
next = "]x",
|
next = "]x",
|
||||||
prev = "[x",
|
prev = "[x",
|
||||||
},
|
},
|
||||||
@ -203,6 +204,7 @@ The following key bindings are available for use with `avante.nvim`:
|
|||||||
| <kbd>c</kbd><kbd>o</kbd> | choose ours |
|
| <kbd>c</kbd><kbd>o</kbd> | choose ours |
|
||||||
| <kbd>c</kbd><kbd>t</kbd> | choose theirs |
|
| <kbd>c</kbd><kbd>t</kbd> | choose theirs |
|
||||||
| <kbd>c</kbd><kbd>b</kbd> | choose both |
|
| <kbd>c</kbd><kbd>b</kbd> | choose both |
|
||||||
|
| <kbd>c</kbd><kbd>c</kbd> | choose cursor |
|
||||||
| <kbd>c</kbd><kbd>0</kbd> | choose none |
|
| <kbd>c</kbd><kbd>0</kbd> | choose none |
|
||||||
| <kbd>]</kbd><kbd>x</kbd> | move to previous conflict |
|
| <kbd>]</kbd><kbd>x</kbd> | move to previous conflict |
|
||||||
| <kbd>[</kbd><kbd>x</kbd> | move to next conflict |
|
| <kbd>[</kbd><kbd>x</kbd> | move to next conflict |
|
||||||
|
@ -97,6 +97,7 @@ M.defaults = {
|
|||||||
theirs = "ct",
|
theirs = "ct",
|
||||||
none = "c0",
|
none = "c0",
|
||||||
both = "cb",
|
both = "cb",
|
||||||
|
cursor = "cc",
|
||||||
next = "]x",
|
next = "]x",
|
||||||
prev = "[x",
|
prev = "[x",
|
||||||
},
|
},
|
||||||
|
@ -26,7 +26,7 @@ local map = vim.keymap.set
|
|||||||
-- Types
|
-- Types
|
||||||
-----------------------------------------------------------------------------//
|
-----------------------------------------------------------------------------//
|
||||||
|
|
||||||
---@alias ConflictSide "'ours'"|"'theirs'"|"'both'"|"'base'"|"'none'"
|
---@alias ConflictSide "'ours'"|"'theirs'"|"'both'"|"'cursor'"|"'base'"|"'none'"
|
||||||
|
|
||||||
--- @class AvanteConflictHighlights
|
--- @class AvanteConflictHighlights
|
||||||
--- @field current string
|
--- @field current string
|
||||||
@ -70,6 +70,7 @@ local SIDES = {
|
|||||||
BOTH = "both",
|
BOTH = "both",
|
||||||
BASE = "base",
|
BASE = "base",
|
||||||
NONE = "none",
|
NONE = "none",
|
||||||
|
CURSOR = "cursor",
|
||||||
}
|
}
|
||||||
|
|
||||||
-- A mapping between the internal names and the display names
|
-- A mapping between the internal names and the display names
|
||||||
@ -79,6 +80,7 @@ local name_map = {
|
|||||||
base = "ancestor",
|
base = "ancestor",
|
||||||
both = "both",
|
both = "both",
|
||||||
none = "none",
|
none = "none",
|
||||||
|
cursor = "cursor",
|
||||||
}
|
}
|
||||||
|
|
||||||
local CURRENT_HL = "AvanteConflictCurrent"
|
local CURRENT_HL = "AvanteConflictCurrent"
|
||||||
@ -329,10 +331,11 @@ local function register_cursor_move_events(bufnr)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local hint = string.format(
|
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.ours,
|
||||||
Config.diff.mappings.theirs,
|
Config.diff.mappings.theirs,
|
||||||
Config.diff.mappings.both,
|
Config.diff.mappings.both,
|
||||||
|
Config.diff.mappings.cursor,
|
||||||
Config.diff.mappings.prev,
|
Config.diff.mappings.prev,
|
||||||
Config.diff.mappings.next
|
Config.diff.mappings.next
|
||||||
)
|
)
|
||||||
@ -424,6 +427,9 @@ local function set_commands()
|
|||||||
command("AvanteConflictChooseBoth", function()
|
command("AvanteConflictChooseBoth", function()
|
||||||
M.choose("both")
|
M.choose("both")
|
||||||
end, { nargs = 0 })
|
end, { nargs = 0 })
|
||||||
|
command("AvanteConflictChooseCursor", function()
|
||||||
|
M.choose("cursor")
|
||||||
|
end, { nargs = 0 })
|
||||||
command("AvanteConflictChooseBase", function()
|
command("AvanteConflictChooseBase", function()
|
||||||
M.choose("base")
|
M.choose("base")
|
||||||
end, { nargs = 0 })
|
end, { nargs = 0 })
|
||||||
@ -451,6 +457,7 @@ local function set_plug_mappings()
|
|||||||
map({ "n", "v" }, "<Plug>(git-conflict-both)", "<Cmd>AvanteConflictChooseBoth<CR>", opts("Choose Both"))
|
map({ "n", "v" }, "<Plug>(git-conflict-both)", "<Cmd>AvanteConflictChooseBoth<CR>", opts("Choose Both"))
|
||||||
map({ "n", "v" }, "<Plug>(git-conflict-none)", "<Cmd>AvanteConflictChooseNone<CR>", opts("Choose None"))
|
map({ "n", "v" }, "<Plug>(git-conflict-none)", "<Cmd>AvanteConflictChooseNone<CR>", opts("Choose None"))
|
||||||
map({ "n", "v" }, "<Plug>(git-conflict-theirs)", "<Cmd>AvanteConflictChooseTheirs<CR>", opts("Choose Theirs"))
|
map({ "n", "v" }, "<Plug>(git-conflict-theirs)", "<Cmd>AvanteConflictChooseTheirs<CR>", opts("Choose Theirs"))
|
||||||
|
map("n", "<Plug>(git-conflict-cursor)", "<Cmd>AvanteConflictChooseCursor<CR>", opts("Choose Cursor"))
|
||||||
map("n", "<Plug>(git-conflict-next-conflict)", "<Cmd>AvanteConflictNextConflict<CR>", opts("Next Conflict"))
|
map("n", "<Plug>(git-conflict-next-conflict)", "<Cmd>AvanteConflictNextConflict<CR>", opts("Next Conflict"))
|
||||||
map("n", "<Plug>(git-conflict-prev-conflict)", "<Cmd>AvanteConflictPrevConflict<CR>", opts("Previous Conflict"))
|
map("n", "<Plug>(git-conflict-prev-conflict)", "<Cmd>AvanteConflictPrevConflict<CR>", opts("Previous Conflict"))
|
||||||
end
|
end
|
||||||
@ -467,6 +474,7 @@ local function setup_buffer_mappings(bufnr)
|
|||||||
map({ "n", "v" }, Config.diff.mappings.none, "<Plug>(git-conflict-none)", opts("Choose None"))
|
map({ "n", "v" }, Config.diff.mappings.none, "<Plug>(git-conflict-none)", opts("Choose None"))
|
||||||
map({ "n", "v" }, Config.diff.mappings.theirs, "<Plug>(git-conflict-theirs)", opts("Choose Theirs"))
|
map({ "n", "v" }, Config.diff.mappings.theirs, "<Plug>(git-conflict-theirs)", opts("Choose Theirs"))
|
||||||
map({ "v", "v" }, Config.diff.mappings.ours, "<Plug>(git-conflict-ours)", opts("Choose Ours"))
|
map({ "v", "v" }, Config.diff.mappings.ours, "<Plug>(git-conflict-ours)", opts("Choose Ours"))
|
||||||
|
map("n", Config.diff.mappings.cursor, "<Plug>(git-conflict-cursor)", opts("Choose Cursor"))
|
||||||
-- map('V', Config.diff.mappings.ours, '<Plug>(git-conflict-ours)', opts('Choose Ours'))
|
-- map('V', Config.diff.mappings.ours, '<Plug>(git-conflict-ours)', opts('Choose Ours'))
|
||||||
map("n", Config.diff.mappings.prev, "<Plug>(git-conflict-prev-conflict)", opts("Previous Conflict"))
|
map("n", Config.diff.mappings.prev, "<Plug>(git-conflict-prev-conflict)", opts("Previous Conflict"))
|
||||||
map("n", Config.diff.mappings.next, "<Plug>(git-conflict-next-conflict)", opts("Next Conflict"))
|
map("n", Config.diff.mappings.next, "<Plug>(git-conflict-next-conflict)", opts("Next Conflict"))
|
||||||
@ -681,6 +689,19 @@ function M.choose(side)
|
|||||||
lines = vim.list_extend(first, second)
|
lines = vim.list_extend(first, second)
|
||||||
elseif side == SIDES.NONE then
|
elseif side == SIDES.NONE then
|
||||||
lines = {}
|
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
|
else
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user