-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: choose under cursor #48
Comments
Until this is officially implemented, here's a solution I came up with by looking at the extmarks under the cursor: vim.keymap.set('n', '<leader>cc', function()
local actions = {
GitConflictCurrent = 'ours',
GitConflictCurrentLabel = 'ours',
GitConflictAncestor = 'base',
GitConflictAncestorLabel = 'base',
GitConflictIncoming = 'theirs',
GitConflictIncomingLabel = 'theirs',
}
local mark = vim.iter(vim.inspect_pos().extmarks):find(function(e)
return e.ns == 'git-conflict' and actions[e.opts.hl_group]
end)
if not mark then
vim.notify('No conflict under cursor', vim.log.levels.WARN)
return
end
require('git-conflict').choose(actions[mark.opts.hl_group])
end) |
Edit: This was a workaround for an issue that has since been fixed. @b0o I found this so helpful! Thank you. I noticed that when my cursor is over the final line <<<<<<< HEAD (Current changes)
-- Changed code that is deleted in new_branch
=======
>>>>>>> new_branch (Incoming changes)
-- Cursor on this ^ line doesn't work But I found you can do something a bit hacky like: if vim.api.nvim_get_current_line():match(">>>>>>>") then
-- Move cursor up, then choose "theirs"
local cursor_pos = vim.api.nvim_win_get_cursor(0)
vim.api.nvim_win_set_cursor(0, { cursor_pos[1] - 1, cursor_pos[2] })
require("git-conflict").choose("theirs")
return
end And you can do something similar for choosing both when on the middle if vim.api.nvim_get_current_line():match("=======") then
require("git-conflict").choose("both")
return
end Put together: vim.keymap.set("n", "<leader>cc", function()
local actions = {
GitConflictCurrent = "ours",
GitConflictCurrentLabel = "ours",
GitConflictAncestor = "base",
GitConflictAncestorLabel = "base",
GitConflictIncoming = "theirs",
GitConflictIncomingLabel = "theirs",
}
local line = vim.api.nvim_get_current_line()
local choose = require("git-conflict").choose
if line:match("=======") then
choose("both")
return
end
if line:match(">>>>>>>") then
local cursor_pos = vim.api.nvim_win_get_cursor(0)
vim.api.nvim_win_set_cursor(0, { cursor_pos[1] - 1, cursor_pos[2] })
choose("theirs")
return
end
local mark = vim.iter(vim.inspect_pos().extmarks):find(
function(e) return e.ns == "git-conflict" and actions[e.opts.hl_group] end
)
if not mark then
vim.notify("No conflict under cursor", vim.log.levels.WARN)
return
end
choose(actions[mark.opts.hl_group])
end) |
Hmm, that's interesting. That sounds like a bug to me. I opened an issue: #84.
Nice idea! |
Good idea to open #84. I have been digging around today and have submitted a couple of pull requests to help with this - it turns out there are two separate issues stopping selection of the final line by extmark:
|
It would be great if there was a command to choose whichever hunk (ours or theirs) is currently under the cursor.
Thanks for developing this awesome plugin 🚀
The text was updated successfully, but these errors were encountered: