Skip to content

Commit

Permalink
fix(preview): fixed mouse clicks in the preview main window. Fixes #484
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jun 6, 2024
1 parent fdcfc5a commit 98d9ed7
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lua/trouble/view/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ local Window = require("trouble.view.window")
---@field first_render trouble.Promise
---@field first_update trouble.Promise
---@field moving uv_timer_t
---@field clicked uv_timer_t
---@field state table<string,any>
---@field _filters table<string, trouble.ViewFilter>
---@field private _main? trouble.Main
Expand Down Expand Up @@ -81,6 +82,7 @@ function M.new(opts)
self:refresh()
end
self.moving = vim.uv.new_timer()
self.clicked = vim.uv.new_timer()
return self
end

Expand Down Expand Up @@ -121,6 +123,17 @@ function M:on_mount()

self:listen()
self.win:on("WinLeave", function()
if self.opts.preview.type == "main" and self.clicked:is_active() and Preview.is_open() then
local main = self.preview_win.opts.win
local preview = self.preview_win.win
if main and preview and vim.api.nvim_win_is_valid(main) and vim.api.nvim_win_is_valid(preview) then
local view = vim.api.nvim_win_call(preview, vim.fn.winsaveview)
vim.api.nvim_win_call(main, function()
vim.fn.winrestview(view)
end)
vim.api.nvim_set_current_win(main)
end
end
Preview.close()
end)

Expand Down Expand Up @@ -177,6 +190,11 @@ function M:on_mount()
for k, v in pairs(self.opts.keys) do
self:map(k, v)
end

self.win:map("<leftmouse>", function()
self.clicked:start(100, 0, function() end)
return "<leftmouse>"
end, { remap = false, expr = true })
end

---@param node? trouble.Node
Expand Down

0 comments on commit 98d9ed7

Please sign in to comment.