Skip to content

Commit 00be1db

Browse files
committed
legacy generate gives defaults when no user mappings
1 parent f073cba commit 00be1db

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

lua/nvim-tree/keymap-legacy.lua

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ local M = {
88
legacy_active = {},
99
}
1010

11+
local BEGIN_ON_ATTACH = [[
12+
local api = require('nvim-tree.api')
13+
14+
local on_attach = function(bufnr)
15+
]]
16+
17+
local END_ON_ATTACH = [[
18+
end
19+
]]
20+
1121
local DEFAULT_ON_ATTACH = [[
1222
-- BEGIN_DEFAULT_ON_ATTACH
1323
vim.keymap.set('n', '<C-]>', api.tree.change_root_to_node, { desc = 'CD', buffer = bufnr, noremap = true, silent = true, nowait = true })
@@ -169,15 +179,11 @@ local function generate_on_attach_function(list, unmapped_keys, remove_defaults)
169179
end
170180

171181
local function generate_on_attach_lua(list, unmapped_keys, remove_defaults)
172-
local lua = [[
173-
local api = require('nvim-tree.api')
174-
175-
local on_attach = function(bufnr)
176-
]]
182+
local lua = BEGIN_ON_ATTACH .. "\n"
177183

178184
if remove_defaults then
179185
-- no defaults
180-
lua = lua .. "\n -- remove_keymaps = true\n"
186+
lua = lua .. "\n -- remove_keymaps = true OR view.mappings.custom_only = true\n"
181187
else
182188
-- defaults with explicit removals
183189
lua = lua .. DEFAULT_ON_ATTACH
@@ -216,12 +222,12 @@ local on_attach = function(bufnr)
216222
[[ end, { desc = '%s', buffer = bufnr, noremap = true, silent = true, nowait = true })]],
217223
m.action
218224
)
219-
.. "\n"
225+
.. "\n\n"
220226
end
221227
end
222228
end
223229

224-
return lua
230+
return lua .. "\n" .. END_ON_ATTACH
225231
end
226232

227233
local function generate_legacy_default_mappings()
@@ -273,6 +279,8 @@ local function generate_legacy_active_mappings(list, defaults, unmapped_keys, re
273279
end
274280

275281
function M.generate_legacy_on_attach(opts)
282+
M.on_attach_lua = BEGIN_ON_ATTACH .. "\n" .. DEFAULT_ON_ATTACH .. "\n" .. END_ON_ATTACH
283+
276284
if type(opts.on_attach) == "function" then
277285
return
278286
end
@@ -300,7 +308,6 @@ function M.generate_on_attach()
300308
local name = "/tmp/my_on_attach.lua"
301309
local file = io.output(name)
302310
io.write(M.on_attach_lua)
303-
io.write "end"
304311
io.close(file)
305312
open_file.fn("edit", name)
306313
end

0 commit comments

Comments
 (0)