Skip to content

Commit 205184a

Browse files
authored
fix: open_files_do_not_replace_types also looks at buftype, which makes terminal work (#805)
1 parent e29ffa9 commit 205184a

File tree

5 files changed

+8
-5
lines changed

5 files changed

+8
-5
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ use {
123123
popup_border_style = "rounded",
124124
enable_git_status = true,
125125
enable_diagnostics = true,
126-
open_files_do_not_replace_filetypes = { "terminal", "trouble", "qf" }, -- when opening files, do not use windows containing these filetypes
126+
open_files_do_not_replace_types = { "terminal", "trouble", "qf" }, -- when opening files, do not use windows containing these filetypes or buftypes
127127
sort_case_insensitive = false, -- used when sorting files and directories in the tree
128128
sort_function = nil , -- use a custom function for sorting files and directories in the tree
129129
-- sort_function = function (a,b)

lua/neo-tree.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ M.get_prior_window = function(ignore_filetypes)
178178
if success and is_valid then
179179
local buf = vim.api.nvim_win_get_buf(last_win)
180180
local ft = vim.api.nvim_buf_get_option(buf, "filetype")
181-
if ignore[ft] ~= true then
181+
local bt = vim.api.nvim_buf_get_option(buf, "buftype") or "normal"
182+
if ignore[ft] ~= true and ignore[bt] ~= true then
182183
return last_win
183184
end
184185
end

lua/neo-tree/defaults.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ local config = {
3434
log_level = "info", -- "trace", "debug", "info", "warn", "error", "fatal"
3535
log_to_file = false, -- true, false, "/path/to/file.log", use :NeoTreeLogs to show the file
3636
open_files_in_last_window = true, -- false = open files in top left window
37-
open_files_do_not_replace_filetypes = { "terminal", "trouble", "qf" }, -- when opening files, do not use windows containing these filetypes
37+
open_files_do_not_replace_types = { "terminal", "trouble", "qf" }, -- when opening files, do not use windows containing these filetypes or buftypes
3838
popup_border_style = "NC", -- "double", "none", "rounded", "shadow", "single" or "solid"
3939
resize_timer_interval = 500, -- in ms, needed for containers to redraw right aligned and faded content
4040
-- set to -1 to disable the resize timer entirely

lua/neo-tree/setup/deprecations.lua

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ M.migrate = function(config)
7070
moved("filesystem.filters", "filesystem.filtered_items")
7171
moved("filesystem.filters.show_hidden", "filesystem.filtered_items.hide_dotfiles", opposite)
7272
moved("filesystem.filters.respect_gitignore", "filesystem.filtered_items.hide_gitignored")
73+
moved("open_files_do_not_replace_filetypes", "open_files_do_not_replace_types")
7374
removed("filesystem.filters.gitignore_source")
7475
removed("filesystem.filter_items.gitignore_source")
7576
renamed_value("filesystem.hijack_netrw_behavior", "open_split", "open_current")

lua/neo-tree/utils.lua

+3-2
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ M.get_appropriate_window = function(state)
461461
-- use last window if possible
462462
local suitable_window_found = false
463463
local nt = require("neo-tree")
464-
local ignore_ft = nt.config.open_files_do_not_replace_filetypes
464+
local ignore_ft = nt.config.open_files_do_not_replace_types
465465
local ignore = M.list_to_dict(ignore_ft)
466466
ignore["neo-tree"] = true
467467
if nt.config.open_files_in_last_window then
@@ -483,7 +483,8 @@ M.get_appropriate_window = function(state)
483483
end
484484
local attempts = 0
485485
while attempts < 5 and not suitable_window_found do
486-
if ignore[vim.bo.filetype] or M.is_floating() then
486+
local bt = vim.bo.buftype or "normal"
487+
if ignore[vim.bo.filetype] or ignore[bt] or M.is_floating() then
487488
attempts = attempts + 1
488489
vim.cmd("wincmd w")
489490
else

0 commit comments

Comments
 (0)