Skip to content

Commit

Permalink
fix: properly exit when trouble is the last window. Fixes #24
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed May 7, 2021
1 parent 1faa347 commit 2b27b96
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lua/trouble/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ function View:on_enter()
end
end

if not vim.api.nvim_win_is_valid(self.parent) then return self:close() end

self.parent_state = {
buf = vim.api.nvim_win_get_buf(self.parent),
cursor = vim.api.nvim_win_get_cursor(self.parent)
Expand Down Expand Up @@ -216,6 +218,7 @@ function View:is_float(win)
end

function View:is_valid_parent(win)
if not vim.api.nvim_win_is_valid(win) then return false end
-- dont do anything for floating windows
if View:is_float(win) then return false end
local buf = vim.api.nvim_win_get_buf(win)
Expand All @@ -230,6 +233,11 @@ function View:on_win_enter()

local current_win = vim.api.nvim_get_current_win()

if vim.fn.winnr('$') == 1 and current_win == self.win then
vim.cmd [[q]]
return
end

if not self:is_valid_parent(current_win) then return end

local current_buf = vim.api.nvim_get_current_buf()
Expand Down Expand Up @@ -371,6 +379,7 @@ function View:toggle_fold()
end

function View:preview()
if not vim.api.nvim_win_is_valid(self.parent) then return end
util.debug("preview")

local item = self:current_item()
Expand Down

0 comments on commit 2b27b96

Please sign in to comment.