Skip to content

Commit

Permalink
feat: open({focus=false}) now works as intended
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Oct 17, 2023
1 parent 02219b5 commit 600fe24
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lua/trouble/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function Trouble.open(...)
config.options.severity = opts.severity
end

opts.focus = true
opts.focus = opts.focus == nil and true or opts.focus
opts.on_open = true

if Trouble.is_open() then
Expand Down
33 changes: 20 additions & 13 deletions lua/trouble/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ local function wipe_rogue_buffer()
end
end

---@return TroubleView
function View:new(opts)
opts = opts or {}

Expand Down Expand Up @@ -141,6 +142,7 @@ function View:setup(opts)
self:set_option("bufhidden", "wipe")
self:set_option("buftype", "nofile")
self:set_option("swapfile", false)
self:set_option("cursorline", true, true)
self:set_option("buflisted", false)
self:set_option("winfixwidth", true, true)
self:set_option("wrap", false, true)
Expand Down Expand Up @@ -361,21 +363,26 @@ end

function View.create(opts)
opts = opts or {}
if opts.win then
View.switch_to(opts.win)
vim.cmd("enew")
else
vim.cmd("below new")
local pos = { bottom = "J", top = "K", left = "H", right = "L" }
vim.cmd("wincmd " .. (pos[config.options.position] or "K"))
end
local buffer = View:new(opts)
buffer:setup(opts)
---@type TroubleView
local view
vim.api.nvim_win_call(0, function()
if opts.win then
View.switch_to(opts.win)
vim.cmd("enew")
else
vim.cmd("below new")
local pos = { bottom = "J", top = "K", left = "H", right = "L" }
vim.cmd("wincmd " .. (pos[config.options.position] or "K"))
end
view = View:new(opts)
view:setup(opts)
end)

if opts and opts.auto then
buffer:switch_to_parent()
if opts.focus == true then
view:focus()
end
return buffer

return view
end

function View:get_cursor()
Expand Down

0 comments on commit 600fe24

Please sign in to comment.