fix(status): Make restoring files available in visual mode (#144)

This commit is contained in:
Nicolas GB
2026-07-24 17:47:24 +02:00
committed by GitHub
parent cf11a4ffec
commit 3d10ae14be
5 changed files with 85 additions and 35 deletions
+22
View File
@@ -1064,4 +1064,26 @@ function M.open_first_conflicted_file(revset)
end
end
--- Extract selected lines from visual mode, and the marks for the start and end lines.
--- @param bufnr integer The buffer number to get the selection from
--- @return string[]|nil The selected lines, or nil if not in visual mode
--- @return integer|nil The start line of the selection (1-based)
--- @return integer|nil The end line of the selection (1-based)
function M.get_visual_selection(bufnr)
local mode = vim.fn.mode()
if mode ~= "v" and mode ~= "V" and mode ~= "\22" then
return nil, nil, nil
end
local selected_start_line = vim.fn.line("v")
local selected_end_line = vim.fn.line(".")
if selected_start_line > selected_end_line then
selected_start_line, selected_end_line = selected_end_line, selected_start_line
end
local lines = vim.api.nvim_buf_get_lines(bufnr, selected_start_line - 1, selected_end_line, false)
return lines, selected_start_line, selected_end_line
end
return M