|
1 | 1 | local fb_actions = require "telescope._extensions.file_browser.actions" |
2 | 2 | local fb_utils = require "telescope._extensions.file_browser.utils" |
| 3 | +local scan = require "plenary.scandir" |
| 4 | +local Path = require "plenary.path" |
3 | 5 |
|
4 | 6 | local action_state = require "telescope.actions.state" |
5 | 7 | local action_set = require "telescope.actions.set" |
@@ -47,10 +49,27 @@ _TelescopeFileBrowserConfig = { |
47 | 49 | local entry = action_state.get_selected_entry() |
48 | 50 | return entry and entry.Path:is_dir() |
49 | 51 | end, function() |
50 | | - local entry = action_state.get_selected_entry() |
51 | | - local path = vim.loop.fs_realpath(entry.path) |
52 | 52 | local current_picker = action_state.get_current_picker(prompt_bufnr) |
53 | 53 | local finder = current_picker.finder |
| 54 | + local entry = action_state.get_selected_entry() |
| 55 | + local path = vim.loop.fs_realpath(entry.path) |
| 56 | + |
| 57 | + if finder.files and finder.collapse_dirs then |
| 58 | + local upwards = path == Path:new(finder.path):parent():absolute() |
| 59 | + while true do |
| 60 | + local dirs = scan.scan_dir(path, { add_dirs = true, depth = 1, hidden = true }) |
| 61 | + if #dirs == 1 and vim.fn.isdirectory(dirs[1]) then |
| 62 | + path = upwards and Path:new(path):parent():absolute() or dirs[1] |
| 63 | + -- make sure it's upper bound (#dirs == 1 implicitly reflects lower bound) |
| 64 | + if path == Path:new(path):parent():absolute() then |
| 65 | + break |
| 66 | + end |
| 67 | + else |
| 68 | + break |
| 69 | + end |
| 70 | + end |
| 71 | + end |
| 72 | + |
54 | 73 | finder.files = true |
55 | 74 | finder.path = path |
56 | 75 | fb_utils.redraw_border_title(current_picker) |
|
101 | 120 |
|
102 | 121 | config.setup = function(opts) |
103 | 122 | -- TODO maybe merge other keys as well from telescope.config |
104 | | - config.values.mappings = vim.tbl_deep_extend( |
105 | | - "force", |
106 | | - config.values.mappings, |
107 | | - require("telescope.config").values.mappings |
108 | | - ) |
| 123 | + config.values.mappings = |
| 124 | + vim.tbl_deep_extend("force", config.values.mappings, require("telescope.config").values.mappings) |
109 | 125 | config.values = vim.tbl_deep_extend("force", config.values, opts) |
110 | 126 |
|
111 | 127 | if config.values.hijack_netrw then |
|
0 commit comments