From 869d396e67024e0d5fa283cab30de42e14012ff1 Mon Sep 17 00:00:00 2001 From: delphinus Date: Sat, 23 Nov 2024 18:44:15 +0900 Subject: [PATCH] hoge --- lua/frecency/entry_maker.lua | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/lua/frecency/entry_maker.lua b/lua/frecency/entry_maker.lua index 90dfc9c..5975c53 100644 --- a/lua/frecency/entry_maker.lua +++ b/lua/frecency/entry_maker.lua @@ -66,7 +66,17 @@ function EntryMaker:create(filepath_formatter, workspaces, workspace_tag) ---@param entry FrecencyEntry ---@return table display = function(entry) - local items = self:items(entry, workspace, workspace_tag, filepath_formatter(workspace)) + ---@type string + local matched + if workspaces then + for _, workspace in ipairs(workspaces) do + if entry.name:find(workspace, 1, true) then + matched = workspace + break + end + end + end + local items = self:items(entry, matched, workspace_tag, filepath_formatter(matched)) return displayer(items) end, } @@ -150,16 +160,21 @@ end ---@param workspace_tag string ---@return integer function EntryMaker:calculate_filter_column_width(workspaces, workspace_tag) - if self:should_show_tail(workspace_tag) then - return #(utils.path_tail(workspace)) + 1 + ---@type string + local longest + for _, workspace in ipairs(workspaces) do + if not longest or #workspace > #longest then + longest = workspace + end end - return #(fs.relative_from_home(workspace)) + 1 + return self:should_show_tail(workspace_tag) and #(utils.path_tail(longest)) + 1 + or #(fs.relative_from_home(longest)) + 1 end ---@private ---@param workspace_tag string ---@return boolean -function EntryMaker:should_show_tail(workspace_tag) +function EntryMaker.should_show_tail(_, workspace_tag) local show_filter_column = config.show_filter_column local filters = type(show_filter_column) == "table" and show_filter_column or { "LSP", "CWD" } return vim.tbl_contains(filters, workspace_tag)