feat(defaults): enable customization of path_display.truncate (#1264)
followup to https://github.com/nvim-telescope/telescope.nvim/pull/1254 and implementation of https://github.com/nvim-telescope/telescope.nvim/pull/1254#issuecomment-922527270
This commit is contained in:
@@ -192,7 +192,8 @@ telescope.setup({opts}) *telescope.setup()*
|
|||||||
- "shorten" only display the first character of each directory in
|
- "shorten" only display the first character of each directory in
|
||||||
the path
|
the path
|
||||||
- "truncate" truncates the start of the path when the whole path will
|
- "truncate" truncates the start of the path when the whole path will
|
||||||
not fit
|
not fit. To increase the the gap between the path and the edge.
|
||||||
|
set truncate to number `truncate = 3`
|
||||||
|
|
||||||
You can also specify the number of characters of each directory name
|
You can also specify the number of characters of each directory name
|
||||||
to keep by setting `path_display.shorten = num`.
|
to keep by setting `path_display.shorten = num`.
|
||||||
|
|||||||
@@ -257,7 +257,8 @@ append(
|
|||||||
- "shorten" only display the first character of each directory in
|
- "shorten" only display the first character of each directory in
|
||||||
the path
|
the path
|
||||||
- "truncate" truncates the start of the path when the whole path will
|
- "truncate" truncates the start of the path when the whole path will
|
||||||
not fit
|
not fit. To increase the the gap between the path and the edge.
|
||||||
|
set truncate to number `truncate = 3`
|
||||||
|
|
||||||
You can also specify the number of characters of each directory name
|
You can also specify the number of characters of each directory name
|
||||||
to keep by setting `path_display.shorten = num`.
|
to keep by setting `path_display.shorten = num`.
|
||||||
|
|||||||
@@ -329,9 +329,10 @@ local is_uri = function(filename)
|
|||||||
return string.match(filename, "^%w+://") ~= nil
|
return string.match(filename, "^%w+://") ~= nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local calc_result_length = function()
|
local calc_result_length = function(truncate_len)
|
||||||
local status = get_status(vim.api.nvim_get_current_buf())
|
local status = get_status(vim.api.nvim_get_current_buf())
|
||||||
return vim.api.nvim_win_get_width(status.results_win) - status.picker.selection_caret:len() - 2
|
local len = vim.api.nvim_win_get_width(status.results_win) - status.picker.selection_caret:len() - 2
|
||||||
|
return type(truncate_len) == "number" and len - truncate_len or len
|
||||||
end
|
end
|
||||||
|
|
||||||
utils.transform_path = function(opts, path)
|
utils.transform_path = function(opts, path)
|
||||||
@@ -371,7 +372,7 @@ utils.transform_path = function(opts, path)
|
|||||||
end
|
end
|
||||||
if vim.tbl_contains(path_display, "truncate") or path_display.truncate then
|
if vim.tbl_contains(path_display, "truncate") or path_display.truncate then
|
||||||
if opts.__length == nil then
|
if opts.__length == nil then
|
||||||
opts.__length = calc_result_length()
|
opts.__length = calc_result_length(path_display.truncate)
|
||||||
end
|
end
|
||||||
transformed_path = truncate(transformed_path, opts.__length, nil, -1)
|
transformed_path = truncate(transformed_path, opts.__length, nil, -1)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user