Skip to content

Commit

Permalink
fix(api): only refresh on open if there's no action. Fixes #488
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jun 7, 2024
1 parent c11dc27 commit 2661f46
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
17 changes: 15 additions & 2 deletions lua/trouble/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ end
-- it will be focused unless `opts.focus = false`.
-- When a view is already open and `opts.new = true`,
-- a new view will be created.
---@param opts? trouble.Mode | { new?: boolean } | string
---@param opts? trouble.Mode | { new?: boolean, refresh?: boolean } | string
---@return trouble.View?
function M.open(opts)
opts = opts or {}
Expand All @@ -55,7 +55,13 @@ function M.open(opts)
view = View.new(_opts)
end
if view then
view:open()
if view:is_open() then
if opts.refresh ~= false then
view:refresh()
end
else
view:open()
end
if _opts.focus ~= false then
view:wait(function()
view.win:focus()
Expand Down Expand Up @@ -107,6 +113,13 @@ end
---@param action trouble.Action.spec
function M._action(action)
return function(opts)
opts = opts or {}
if type(opts) == "string" then
opts = { mode = opts }
end
opts = vim.tbl_deep_extend("force", {
refresh = false,
}, opts)
local view = M.open(opts)
if view then
view:action(action, opts)
Expand Down
5 changes: 4 additions & 1 deletion lua/trouble/view/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,12 @@ function M:help()
win:map("q", win.close)
end

function M:is_open()
return self.win:valid()
end

function M:open()
if self.win:valid() then
self:refresh()
return self
end
self
Expand Down

0 comments on commit 2661f46

Please sign in to comment.