-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(make_entry): ordinal & display for higher depth search
- Loading branch information
Showing
5 changed files
with
85 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
lua/telescope/_extensions/file_browser/make_entry_utils.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
local Path = require "plenary.path" | ||
local fb_utils = require "telescope._extensions.file_browser.utils" | ||
|
||
local os_sep = Path.path.sep | ||
local os_sep_len = #os_sep | ||
|
||
local M = {} | ||
|
||
--- compute ordinal path | ||
--- accounts for `auto_depth` option | ||
---@param path string | ||
---@param cwd string | ||
---@param parent string | ||
---@return string | ||
M.get_ordinal_path = function(path, cwd, parent) | ||
path = fb_utils.sanitize_path_str(path) | ||
if path == cwd then | ||
return "." | ||
elseif path == parent then | ||
return ".." | ||
end | ||
|
||
local cwd_substr = #cwd + 1 | ||
print(cwd_substr) | ||
cwd_substr = cwd:sub(-1, -1) ~= os_sep and cwd_substr + os_sep_len or cwd_substr | ||
|
||
return path:sub(cwd_substr, -1) | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
local me_utils = require "telescope._extensions.file_browser.make_entry_utils" | ||
|
||
describe("get_ordinal_path", function() | ||
it("shows '.' for cwd", function() | ||
assert.are.same(".", me_utils.get_ordinal_path("/home/a/b/c", "/home/a/b/c", "/home/a/b")) | ||
assert.are.same(".", me_utils.get_ordinal_path("/home/a/b/c", "/home/a/b/c", "/home/a/b")) | ||
end) | ||
|
||
it("shows '..' for parent path", function() | ||
assert.are.same("..", me_utils.get_ordinal_path("/home/a/b", "/home/a/b/c", "/home/a/b")) | ||
end) | ||
|
||
it("shows basename for cwd file", function() | ||
assert.are.same("file.txt", me_utils.get_ordinal_path("/home/a/b/c/file.txt", "/home/a/b/c", "/home/a/b")) | ||
end) | ||
|
||
it("handles depths greater than 1", function() | ||
assert.are.same("d/file.txt", me_utils.get_ordinal_path("/home/a/b/c/d/file.txt", "/home/a/b/c", "/home/a/b")) | ||
end) | ||
|
||
it("handles duplicate os_sep", function() | ||
assert.are.same("file.txt", me_utils.get_ordinal_path("/home/a/b/c//file.txt", "/home/a/b/c", "/home/a/b")) | ||
end) | ||
end) |