Skip to content

Commit

Permalink
fix: do not open_automatic in unsupported buffers (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Dec 1, 2022
1 parent 38c6fe1 commit 047e19d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lua/aerial/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ end
---@return boolean
M.is_ignored_buf = function(bufnr)
bufnr = bufnr or 0
if not vim.api.nvim_buf_is_valid(bufnr) then
return true
end
local filetype = vim.api.nvim_buf_get_option(bufnr, "filetype")
-- Never ignore aerial buffers
if filetype == "aerial" then
Expand Down
3 changes: 2 additions & 1 deletion lua/aerial/window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ end
---@param bufnr? integer
---@return boolean
M.maybe_open_automatic = function(bufnr)
if config.open_automatic(bufnr or 0) then
bufnr = bufnr or 0
if config.open_automatic(bufnr) and backends.get(bufnr) then
M.open(false)
return true
else
Expand Down
24 changes: 24 additions & 0 deletions tests/attach_and_events_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,28 @@ a.describe("config attach_mode = 'global'", function()
assert.falsy(vim.api.nvim_win_is_valid(aerial_win))
end
)

a.it("open_automatic = true opens aerial when entering supported buffer", function()
aerial.setup({
lazy_load = false,
attach_mode = "global",
open_automatic = true,
})
vim.cmd.edit({ args = { "README.md" } })
sleep(30)
local aerial_win = util.get_aerial_win(0)
assert.truthy(vim.api.nvim_win_is_valid(aerial_win))
end)

a.it("open_automatic = true does not open aerial when entering unsupported buffer", function()
aerial.setup({
lazy_load = false,
attach_mode = "global",
open_automatic = true,
})
vim.cmd.edit({ args = { "LICENSE" } })
sleep(30)
local aerial_win = util.get_aerial_win(0)
assert.is_nil(aerial_win)
end)
end)
2 changes: 1 addition & 1 deletion tests/open_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require("plenary.async").tests.add_to_env()
local aerial = require("aerial")
local test_util = require("tests.test_util")

a.describe("config", function()
a.describe("layout", function()
after_each(function()
test_util.reset_editor()
end)
Expand Down
2 changes: 1 addition & 1 deletion tests/window_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local config = require("aerial.config")
local data = require("aerial.data")
local window = require("aerial.window")

describe("config", function()
describe("symbol positions", function()
before_each(function()
config.setup()
end)
Expand Down

0 comments on commit 047e19d

Please sign in to comment.