54
54
local fb_actions = require " telescope._extensions.file_browser.actions"
55
55
local fb_finders = require " telescope._extensions.file_browser.finders"
56
56
local fb_picker = require " telescope._extensions.file_browser.picker"
57
- local fb_utils = require " telescope._extensions.file_browser.utils"
58
-
59
- local action_state = require " telescope.actions.state"
60
- local action_set = require " telescope.actions.set"
61
- local state = require " telescope.state"
62
- local Path = require " plenary.path"
63
-
64
- local pconf = {
65
- mappings = {
66
- [" i" ] = {
67
- [" <A-c>" ] = fb_actions .create ,
68
- [" <A-r>" ] = fb_actions .rename ,
69
- [" <A-m>" ] = fb_actions .move ,
70
- [" <A-y>" ] = fb_actions .copy ,
71
- [" <A-d>" ] = fb_actions .remove ,
72
- [" <C-o>" ] = fb_actions .open ,
73
- [" <C-g>" ] = fb_actions .goto_parent_dir ,
74
- [" <C-e>" ] = fb_actions .goto_home_dir ,
75
- [" <C-w>" ] = fb_actions .goto_cwd ,
76
- [" <C-t>" ] = fb_actions .change_cwd ,
77
- [" <C-f>" ] = fb_actions .toggle_browser ,
78
- [" <C-h>" ] = fb_actions .toggle_hidden ,
79
- [" <C-s>" ] = fb_actions .toggle_all ,
80
- },
81
- [" n" ] = {
82
- [" c" ] = fb_actions .create ,
83
- [" r" ] = fb_actions .rename ,
84
- [" m" ] = fb_actions .move ,
85
- [" y" ] = fb_actions .copy ,
86
- [" d" ] = fb_actions .remove ,
87
- [" o" ] = fb_actions .open ,
88
- [" g" ] = fb_actions .goto_parent_dir ,
89
- [" e" ] = fb_actions .goto_home_dir ,
90
- [" w" ] = fb_actions .goto_cwd ,
91
- [" t" ] = fb_actions .change_cwd ,
92
- [" f" ] = fb_actions .toggle_browser ,
93
- [" h" ] = fb_actions .toggle_hidden ,
94
- [" s" ] = fb_actions .toggle_all ,
95
- },
96
- },
97
- attach_mappings = function (prompt_bufnr , _ )
98
- action_set .select :replace_if (function ()
99
- -- test whether selected entry is directory
100
- local entry = action_state .get_selected_entry ()
101
- local current_picker = action_state .get_current_picker (prompt_bufnr )
102
- local finder = current_picker .finder
103
- return (finder .files and entry == nil ) or (entry and entry .Path :is_dir ())
104
- end , function ()
105
- local entry = action_state .get_selected_entry ()
106
- if entry and entry .Path :is_dir () then
107
- local path = vim .loop .fs_realpath (entry .path )
108
- local current_picker = action_state .get_current_picker (prompt_bufnr )
109
- local finder = current_picker .finder
110
- finder .files = true
111
- finder .path = path
112
- fb_utils .redraw_border_title (current_picker )
113
- current_picker :refresh (finder , { reset_prompt = true , multi = current_picker ._multi })
114
- else
115
- -- Create file from prompt
116
- -- TODO notification about created file once PR lands
117
- local current_picker = action_state .get_current_picker (prompt_bufnr )
118
- local finder = current_picker .finder
119
- if finder .files then
120
- local file = Path :new { finder .path , current_picker :_get_prompt () }
121
- if not fb_utils .is_dir (file .filename ) then
122
- file :touch { parents = true }
123
- else
124
- Path :new (file .filename :sub (1 , - 2 )):mkdir { parents = true }
125
- end
126
- local path = file :absolute ()
127
- -- pretend new file path is entry
128
- state .set_global_key (" selected_entry" , { path = path , filename = path , Path = file })
129
- -- select as if were proper entry to support eg changing into created folder
130
- action_set .select (prompt_bufnr , " default" )
131
- end
132
- end
133
- end )
134
- return true
135
- end ,
136
- }
137
-
138
- local fb_setup = function (opts )
139
- -- TODO maybe merge other keys as well from telescope.config
140
- pconf .mappings = vim .tbl_deep_extend (" force" , pconf .mappings , require (" telescope.config" ).values .mappings )
141
- pconf = vim .tbl_deep_extend (" force" , pconf , opts )
142
- end
57
+ local fb_config = require " telescope._extensions.file_browser.config"
143
58
144
59
local file_browser = function (opts )
145
60
opts = opts or {}
146
61
local defaults = (function ()
147
- if pconf .theme then
148
- return require (" telescope.themes" )[" get_" .. pconf . theme ](pconf )
62
+ if fb_config . values .theme then
63
+ return require (" telescope.themes" )[" get_" .. fb_config . values . theme ](fb_config )
149
64
end
150
- return vim .deepcopy (pconf )
65
+ return vim .deepcopy (fb_config . values )
151
66
end )()
152
67
153
- if pconf .mappings then
68
+ if fb_config . values .mappings then
154
69
defaults .attach_mappings = function (prompt_bufnr , map )
155
- if pconf .attach_mappings then
156
- pconf .attach_mappings (prompt_bufnr , map )
70
+ if fb_config . values .attach_mappings then
71
+ fb_config . values .attach_mappings (prompt_bufnr , map )
157
72
end
158
- for mode , tbl in pairs (pconf .mappings ) do
73
+ for mode , tbl in pairs (fb_config . values .mappings ) do
159
74
for key , action in pairs (tbl ) do
160
75
map (mode , key , action )
161
76
end
@@ -176,7 +91,7 @@ local file_browser = function(opts)
176
91
end
177
92
178
93
return telescope .register_extension {
179
- setup = fb_setup ,
94
+ setup = fb_config . setup ,
180
95
exports = {
181
96
file_browser = file_browser ,
182
97
actions = fb_actions ,
0 commit comments