fix component(filename) add separator between filename and icons (#812)

This makes it behave like the default statusline.

fixes #794
This commit is contained in:
zappolowski 2022-09-10 11:39:38 +02:00 committed by GitHub
parent a03f31f566
commit 5d133a1ef2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 7 deletions

View File

@ -85,19 +85,21 @@ M.update_status = function(self)
data = shorten_path(data, path_separator, estimated_space_available)
end
local symbols = {}
if self.options.file_status then
if vim.bo.modified then
data = data .. self.options.symbols.modified
table.insert(symbols, self.options.symbols.modified)
end
if vim.bo.modifiable == false or vim.bo.readonly == true then
data = data .. self.options.symbols.readonly
table.insert(symbols, self.options.symbols.readonly)
end
end
if self.options.newfile_status and is_new_file() then
data = data .. self.options.symbols.newfile
table.insert(symbols, self.options.symbols.newfile)
end
return data
return data .. (#symbols > 0 and ' ' .. table.concat(symbols, '') or '')
end
return M

View File

@ -478,10 +478,25 @@ describe('Filename component', function()
vim.bo.modified = false
assert_component('filename', opts, 'test-file.txt')
vim.bo.modified = true
assert_component('filename', opts, 'test-file.txt[+]')
vim.bo.modified = false
assert_component('filename', opts, 'test-file.txt [+]')
vim.bo.ro = true
assert_component('filename', opts, 'test-file.txt[-]')
assert_component('filename', opts, 'test-file.txt [+][-]')
vim.bo.modified = false
assert_component('filename', opts, 'test-file.txt [-]')
vim.cmd(':bdelete!')
end)
it('can show new_file_status', function ()
local opts = build_component_opts {
component_separators = { left = '', right = '' },
padding = 0,
newfile_status = true,
path = 0,
}
vim.cmd(':e new-file.txt')
assert_component('filename', opts, 'new-file.txt [New]')
vim.bo.modified = true
assert_component('filename', opts, 'new-file.txt [+][New]')
vim.cmd(':bdelete!')
end)