From 0dce6906b6ea50698e6f983de2c640c6c7d62e4e Mon Sep 17 00:00:00 2001 From: Jaehaks Date: Wed, 15 May 2024 22:08:11 +0900 Subject: [PATCH 1/6] fix : show short_file_name properly in Windows /// Problem: 1) Set configuration doesn't be applied in M.toggle_quick_menu() It makes short_file_name option don't work 2) The number of slash('/') doesn't show properly in short_file_name mode. On Windows, sometimes the file path has both '/' and '\\' as delimiter because of neovim inherit problem. /// Solution: 1) call get_config() function in toggle_quick_menu again. 2) On Windows, backslash of file path in buffer list is replaced by '/' --- lua/buffer_manager/ui.lua | 1 + lua/buffer_manager/utils.lua | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/lua/buffer_manager/ui.lua b/lua/buffer_manager/ui.lua index cd4094a..604c339 100644 --- a/lua/buffer_manager/ui.lua +++ b/lua/buffer_manager/ui.lua @@ -299,6 +299,7 @@ end function M.toggle_quick_menu() log.trace("toggle_quick_menu()") + config = buffer_manager.get_config() -- update configuration if Buffer_manager_win_id ~= nil and vim.api.nvim_win_is_valid(Buffer_manager_win_id) then if vim.api.nvim_buf_get_changedtick(vim.fn.bufnr()) > 0 then M.on_menu_save() diff --git a/lua/buffer_manager/utils.lua b/lua/buffer_manager/utils.lua index 7454fec..c85f193 100644 --- a/lua/buffer_manager/utils.lua +++ b/lua/buffer_manager/utils.lua @@ -30,6 +30,10 @@ end function M.get_short_file_name(file, current_short_fns) + local has_win = vim.fn.has('win32') == 1 + if has_win then + file = file:gsub('\\','/') + end local short_name = nil -- Get normalized file path file = M.normalize_path(file) From 2661f660093dcb9236f58f22c12de1ed07375a92 Mon Sep 17 00:00:00 2001 From: Jaehaks Date: Fri, 20 Sep 2024 22:09:19 +0900 Subject: [PATCH 2/6] fix(utils) : show parent folder if there are same named file --- lua/buffer_manager/utils.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lua/buffer_manager/utils.lua b/lua/buffer_manager/utils.lua index c85f193..5e07d96 100644 --- a/lua/buffer_manager/utils.lua +++ b/lua/buffer_manager/utils.lua @@ -45,29 +45,31 @@ function M.get_short_file_name(file, current_short_fns) -- insert firts char only table.insert(folders, folder) end + -- folders : table which is constitute of file path every '/' + -- why does this function call files with multiple times? -- File to string file = tostring(file) -- Count the number of slashes in the relative file path local slash_count = 0 - for _ in string.gmatch(file, "/") do + for _ in string.gmatch(file, "/") do -- he makes 'folders', but why do this? slash_count = slash_count + 1 end if slash_count == 0 then short_name = M.get_file_name(file) else -- Return the file name preceded by the number of slashes - short_name = slash_count .. "|" .. M.get_file_name(file) + short_name = slash_count .. "|" .. M.get_file_name(file) -- get file name only regardless of path end -- Check if the file name is already in the list of short file names -- If so, return the short file name with one number in front of it - local i = 1 + local i = #folders-1 while key_in_table(short_name, current_short_fns) do local folder = folders[i] if folder == nil then folder = i end - short_name = short_name.." ("..folder..")" - i = i + 1 + short_name = short_name.." ("..folder.."/)" + i = i - 1 end return short_name end From 56b0f2b8c1395f61ff8916c07505a9038edc7126 Mon Sep 17 00:00:00 2001 From: Jaehaks Date: Fri, 20 Sep 2024 22:41:15 +0900 Subject: [PATCH 3/6] fix(utils) : show parents continuously even though slash_count is same 1) show parents if the file name is same even though slash_count is same 6|test.lua 7|test.lua (test/) 2) show parents continuously if the parents are same 6|test.lua 7|test.lua (kkk/test/) --- lua/buffer_manager/utils.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lua/buffer_manager/utils.lua b/lua/buffer_manager/utils.lua index 5e07d96..3162c02 100644 --- a/lua/buffer_manager/utils.lua +++ b/lua/buffer_manager/utils.lua @@ -63,12 +63,15 @@ function M.get_short_file_name(file, current_short_fns) -- Check if the file name is already in the list of short file names -- If so, return the short file name with one number in front of it local i = #folders-1 + local filename = short_name + local dirname = '' while key_in_table(short_name, current_short_fns) do local folder = folders[i] if folder == nil then folder = i end - short_name = short_name.." ("..folder.."/)" + dirname = folder .. '/' .. dirname + short_name = filename .. ' (' .. dirname .. ')' i = i - 1 end return short_name From 0f4f68352e4f20f522649d2b597c4d16bd27edec Mon Sep 17 00:00:00 2001 From: Jaehaks Date: Fri, 20 Sep 2024 22:46:17 +0900 Subject: [PATCH 4/6] fix(utils) : show parents continuously even though slash_count is same it is same with #56b0f2b But I missed this file update --- lua/buffer_manager/ui.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/buffer_manager/ui.lua b/lua/buffer_manager/ui.lua index 604c339..71574d3 100644 --- a/lua/buffer_manager/ui.lua +++ b/lua/buffer_manager/ui.lua @@ -117,7 +117,7 @@ local function get_mark_by_name(name, specific_marks) else if config.short_file_names then ref_name = utils.get_short_file_name(mark.filename, current_short_fns) - current_short_fns[ref_name] = true + current_short_fns[ref_name:gsub('^%d+|', '')] = true elseif config.format_function then ref_name = config.format_function(mark.filename) else @@ -347,7 +347,7 @@ function M.toggle_quick_menu() if not string_starts(display_filename, "term://") then if config.short_file_names then display_filename = utils.get_short_file_name(display_filename, current_short_fns) - current_short_fns[display_filename] = true + current_short_fns[display_filename:gsub('^%d+|', '')] = true elseif config.format_function then display_filename = config.format_function(display_filename) else From 0d87a7e7034229c9281d8cce44db5668ea8e6849 Mon Sep 17 00:00:00 2001 From: Jaehaks Date: Fri, 20 Sep 2024 22:50:56 +0900 Subject: [PATCH 5/6] fix(utils) : fix my mistake at #56b0f2b --- lua/buffer_manager/utils.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/buffer_manager/utils.lua b/lua/buffer_manager/utils.lua index 3162c02..6554151 100644 --- a/lua/buffer_manager/utils.lua +++ b/lua/buffer_manager/utils.lua @@ -63,9 +63,9 @@ function M.get_short_file_name(file, current_short_fns) -- Check if the file name is already in the list of short file names -- If so, return the short file name with one number in front of it local i = #folders-1 - local filename = short_name + local filename = short_name:gsub('^%d+|', '') local dirname = '' - while key_in_table(short_name, current_short_fns) do + while key_in_table(short_name:gsub('^%d+|', ''), current_short_fns) do local folder = folders[i] if folder == nil then folder = i From 2e351abf7a097a8952ea3c7289c9354906307f8c Mon Sep 17 00:00:00 2001 From: Jaehaks Date: Fri, 20 Sep 2024 22:53:26 +0900 Subject: [PATCH 6/6] fix(utils) : another mistake... #0d87a7e --- lua/buffer_manager/utils.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/buffer_manager/utils.lua b/lua/buffer_manager/utils.lua index 6554151..af7490e 100644 --- a/lua/buffer_manager/utils.lua +++ b/lua/buffer_manager/utils.lua @@ -63,7 +63,7 @@ function M.get_short_file_name(file, current_short_fns) -- Check if the file name is already in the list of short file names -- If so, return the short file name with one number in front of it local i = #folders-1 - local filename = short_name:gsub('^%d+|', '') + local filename = short_name local dirname = '' while key_in_table(short_name:gsub('^%d+|', ''), current_short_fns) do local folder = folders[i]