Skip to content

Commit

Permalink
(mini.files) BREAKING: Make already present unlisted buffer listed.
Browse files Browse the repository at this point in the history
Details:
- Resolves #470.
  • Loading branch information
echasnovski committed Oct 12, 2023
1 parent ceaa093 commit 751d565
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

- BREAKING: Stop supporting deprecated 'HiPhish/nvim-ts-rainbow2'.

## mini.files

- BREAKING: Opening file which is present in unlisted buffer now makes the buffer listed.

## mini.hues

- BREAKING: Stop supporting deprecated 'HiPhish/nvim-ts-rainbow2'.
Expand Down
3 changes: 2 additions & 1 deletion lua/mini/files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,8 @@ H.explorer_open_file = function(explorer, path)
-- `:edit` call and avoids some problems with auto-root from 'mini.misc'.
local path_buf_id
for _, buf_id in ipairs(vim.api.nvim_list_bufs()) do
if H.is_valid_buf(buf_id) and vim.api.nvim_buf_get_name(buf_id) == path then path_buf_id = buf_id end
local is_target = H.is_valid_buf(buf_id) and vim.bo[buf_id].buflisted and vim.api.nvim_buf_get_name(buf_id) == path
if is_target then path_buf_id = buf_id end
end

if path_buf_id ~= nil then
Expand Down
15 changes: 12 additions & 3 deletions tests/test_files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1122,18 +1122,27 @@ T['go_in()']['works on files with problematic names'] = function()
eq(get_lines(), { 'aaa' })
end

T['go_in()']['uses already opened buffer without `:edit`'] = function()
T['go_in()']['uses already opened listed buffer without `:edit`'] = function()
local temp_dir = make_temp_dir('temp', { 'file' })
local file_path = join_path(temp_dir, 'file')

child.cmd('edit ' .. vim.fn.fnameescape(file_path))
local buf_id = child.api.nvim_get_current_buf()
child.fn.writefile({ 'New changes' }, file_path)

open(temp_dir)
child.fn.writefile({ 'New changes' }, file_path)
go_in()
-- If `:edit` was reused, then content would have changed
-- If `:edit` was used, then content would have changed
eq(child.api.nvim_buf_get_lines(buf_id, 0, -1, false), { '' })
close(temp_dir)

-- Should make unlisted buffer become listed
child.cmd('bdelete ' .. buf_id)
eq(child.api.nvim_buf_get_option(buf_id, 'buflisted'), false)

open(temp_dir)
go_in()
eq(child.api.nvim_buf_get_option(buf_id, 'buflisted'), true)
end

T['go_in()']['uses proper target window'] = function()
Expand Down

0 comments on commit 751d565

Please sign in to comment.