mirror of
https://github.com/folke/snacks.nvim
synced 2025-12-23 08:47:57 +00:00
feat(debug): allow debug evaluation of block selections (#1331)
## Description This PR adds basic support for visual block selections to `Snacks.debug.run()`. This is useful when code doesn't start at the beginning of a line, such as in comment blocks. ## Related Issue(s) <!-- If this PR fixes any issues, please link to the issue here. - Fixes #<issue_number> --> ## Screenshots <!-- Add screenshots of the changes if applicable. --> <img width="271" alt="Screenshot 2025-02-19 at 23 02 35" src="https://github.com/user-attachments/assets/5a440b32-6846-4345-b105-42e64796ac65" />
This commit is contained in:
parent
ccca140c2b
commit
231ffae08d
1 changed files with 15 additions and 0 deletions
|
|
@ -98,6 +98,21 @@ function M.run(opts)
|
|||
table.insert(lines, 1, "")
|
||||
end
|
||||
vim.fn.feedkeys("gv", "nx")
|
||||
elseif mode == "\22" then
|
||||
-- Yank the visual selection to handle irregularly shaped blocks
|
||||
local tmp = vim.fn.getreginfo("*")
|
||||
vim.cmd('normal! "*y')
|
||||
lines = vim.fn.getreginfo("*").regcontents
|
||||
vim.fn.setreg("*", tmp.regcontents, tmp.regtype)
|
||||
|
||||
-- Insert empty lines to keep the line numbers
|
||||
local from = vim.api.nvim_buf_get_mark(buf, "<")
|
||||
for _ = 1, from[1] - 1 do
|
||||
table.insert(lines, 1, "")
|
||||
end
|
||||
|
||||
-- Restore the selection
|
||||
vim.fn.feedkeys("gv", "nx")
|
||||
else
|
||||
lines = vim.api.nvim_buf_get_lines(buf, 0, -1, false)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue