From 5d133a1ef22422e769d5affdd089fdda595f5f93 Mon Sep 17 00:00:00 2001 From: zappolowski Date: Sat, 10 Sep 2022 11:39:38 +0200 Subject: [PATCH] fix component(filename) add separator between filename and icons (#812) This makes it behave like the default statusline. fixes #794 --- lua/lualine/components/filename.lua | 10 ++++++---- tests/spec/component_spec.lua | 21 ++++++++++++++++++--- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/lua/lualine/components/filename.lua b/lua/lualine/components/filename.lua index 1d9232f..e35b5d5 100644 --- a/lua/lualine/components/filename.lua +++ b/lua/lualine/components/filename.lua @@ -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 diff --git a/tests/spec/component_spec.lua b/tests/spec/component_spec.lua index f4f6634..d0a2cc2 100644 --- a/tests/spec/component_spec.lua +++ b/tests/spec/component_spec.lua @@ -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)