From ef75145f805717a647e8e323e5973cb23f8d0492 Mon Sep 17 00:00:00 2001 From: Anton Date: Sun, 21 Apr 2024 00:59:36 +0200 Subject: [PATCH] fix(utils): transform_path filename_first composability (#3065) * Moves filename_first to last position to fix issues with composing other options * Adds comment --- lua/telescope/utils.lua | 42 +++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/lua/telescope/utils.lua b/lua/telescope/utils.lua index 89af6b4..d14992f 100644 --- a/lua/telescope/utils.lua +++ b/lua/telescope/utils.lua @@ -307,6 +307,28 @@ utils.transform_path = function(opts, path) transformed_path = Path:new(transformed_path):make_relative(cwd) end + if vim.tbl_contains(path_display, "shorten") or path_display["shorten"] ~= nil then + if type(path_display["shorten"]) == "table" then + local shorten = path_display["shorten"] + transformed_path = Path:new(transformed_path):shorten(shorten.len, shorten.exclude) + else + local length = type(path_display["shorten"]) == "number" and path_display["shorten"] + transformed_path = Path:new(transformed_path):shorten(length) + end + end + + if vim.tbl_contains(path_display, "truncate") or path_display.truncate then + if opts.__length == nil then + opts.__length = calc_result_length(path_display.truncate) + end + if opts.__prefix == nil then + opts.__prefix = 0 + end + transformed_path = truncate(transformed_path, opts.__length - opts.__prefix, nil, -1) + end + + -- IMPORTANT: filename_first needs to be the last option. Otherwise the + -- other options will not be displayed correctly. if vim.tbl_contains(path_display, "filename_first") or path_display["filename_first"] ~= nil then local reverse_directories = false @@ -337,26 +359,6 @@ utils.transform_path = function(opts, path) path_style = { { { #filename, #transformed_path }, "TelescopeResultsComment" } } end - - if vim.tbl_contains(path_display, "shorten") or path_display["shorten"] ~= nil then - if type(path_display["shorten"]) == "table" then - local shorten = path_display["shorten"] - transformed_path = Path:new(transformed_path):shorten(shorten.len, shorten.exclude) - else - local length = type(path_display["shorten"]) == "number" and path_display["shorten"] - transformed_path = Path:new(transformed_path):shorten(length) - end - end - - if vim.tbl_contains(path_display, "truncate") or path_display.truncate then - if opts.__length == nil then - opts.__length = calc_result_length(path_display.truncate) - end - if opts.__prefix == nil then - opts.__prefix = 0 - end - transformed_path = truncate(transformed_path, opts.__length - opts.__prefix, nil, -1) - end end return transformed_path, path_style