Replies: 2 comments 3 replies
-
|
I just tried it and |
Beta Was this translation helpful? Give feedback.
3 replies
-
|
Don't know if this is still relevant / will help someone, but I managed to make it work today. --- Delete items from Trouble quickfix window.
--- @param ids string[] List of item ids to be deleted.
local function delete(ids)
local trouble = require 'trouble'
--- @param item trouble.Item
local items = vim.tbl_filter(function(item)
return not vim.list_contains(ids, item.id)
end, trouble.get_items())
--- @param item trouble.Item
--- @type vim.quickfix.entry[]
local qf_entries = vim.tbl_map(function(item)
return item.item
end, items)
vim.fn.setqflist(qf_entries, 'r')
trouble.refresh()
end
-- Add these keys to the Trouble config options.
local keys = {
['d'] = {
--- @param view trouble.View
action = function(view)
-- Update this condition if you use `qflist`.
if view.opts.mode ~= 'quickfix' then
print 'Deletions only work in quickfix windows!'
return
end
local selection = view:selection()
--- @type string[]
local ids = {}
for _, node in ipairs(selection) do
--- @param item trouble.Item
local item_ids = vim.tbl_map(function(item)
return item.id
end, node:flatten())
vim.list_extend(ids, item_ids)
end
delete(ids)
end,
desc = 'Delete selected nodes',
},
['dd'] = {
--- @param view trouble.View
action = function(view)
-- Update this condition if you use `qflist`.
if view.opts.mode ~= 'quickfix' then
print 'Deletions only work in quickfix windows!'
return
end
local at = view:at()
if at.node ~= nil then
--- @param item trouble.Item
local item_ids = vim.tbl_map(function(item)
return item.id
end, at.node:flatten())
delete(item_ids)
else
print "Couldn't get current node"
end
end,
desc = 'Delete the node under the cursor',
},
}For the full trouble setup, see my config. If you use (Might not work properly with a filtered Trouble quickfix window, haven't tested that.) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Is it possible to delete entries from an existing list like the quickfix list? With the native quickfix window, I was able to configure
ddto remove entries like so:It would be cool if Trouble could also do that.
Beta Was this translation helpful? Give feedback.
All reactions