Skip to content

Commit 748aff5

Browse files
committed
chore(#3196): move utils.move_missing_val to legacy
1 parent 666ddeb commit 748aff5

File tree

2 files changed

+44
-45
lines changed

2 files changed

+44
-45
lines changed

lua/nvim-tree/legacy.lua

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,58 @@
1-
local utils = require("nvim-tree.utils")
21
local notify = require("nvim-tree.notify")
32

43
local M = {}
54

5+
--- Move a value from src to dst if value is nil on dst.
6+
--- Remove value from src
7+
---@param src table to copy from
8+
---@param src_path string dot separated string of sub-tables
9+
---@param src_pos string value pos
10+
---@param dst table to copy to
11+
---@param dst_path string dot separated string of sub-tables, created when missing
12+
---@param dst_pos string value pos
13+
---@param remove boolean
14+
local function move(src, src_path, src_pos, dst, dst_path, dst_pos, remove)
15+
for pos in string.gmatch(src_path, "([^%.]+)%.*") do
16+
if src[pos] and type(src[pos]) == "table" then
17+
src = src[pos]
18+
else
19+
return
20+
end
21+
end
22+
local src_val = src[src_pos]
23+
if src_val == nil then
24+
return
25+
end
26+
27+
dst = M.table_create_missing(dst, dst_path)
28+
if dst[dst_pos] == nil then
29+
dst[dst_pos] = src_val
30+
end
31+
32+
if remove then
33+
src[src_pos] = nil
34+
end
35+
end
36+
637
-- silently move, please add to help nvim-tree-legacy-opts
738
local function refactored(opts)
839
-- 2022/06/20
9-
utils.move_missing_val(opts, "update_focused_file", "update_cwd", opts, "update_focused_file", "update_root", true)
10-
utils.move_missing_val(opts, "", "update_cwd", opts, "", "sync_root_with_cwd", true)
40+
move(opts, "update_focused_file", "update_cwd", opts, "update_focused_file", "update_root", true)
41+
move(opts, "", "update_cwd", opts, "", "sync_root_with_cwd", true)
1142

1243
-- 2022/11/07
13-
utils.move_missing_val(opts, "", "open_on_tab", opts, "tab.sync", "open", false)
14-
utils.move_missing_val(opts, "", "open_on_tab", opts, "tab.sync", "close", true)
15-
utils.move_missing_val(opts, "", "ignore_buf_on_tab_change", opts, "tab.sync", "ignore", true)
44+
move(opts, "", "open_on_tab", opts, "tab.sync", "open", false)
45+
move(opts, "", "open_on_tab", opts, "tab.sync", "close", true)
46+
move(opts, "", "ignore_buf_on_tab_change", opts, "tab.sync", "ignore", true)
1647

1748
-- 2022/11/22
18-
utils.move_missing_val(opts, "renderer", "root_folder_modifier", opts, "renderer", "root_folder_label", true)
49+
move(opts, "renderer", "root_folder_modifier", opts, "renderer", "root_folder_label", true)
1950

2051
-- 2023/01/01
21-
utils.move_missing_val(opts, "update_focused_file", "debounce_delay", opts, "view", "debounce_delay", true)
52+
move(opts, "update_focused_file", "debounce_delay", opts, "view", "debounce_delay", true)
2253

2354
-- 2023/01/08
24-
utils.move_missing_val(opts, "trash", "require_confirm", opts, "ui.confirm", "trash", true)
55+
move(opts, "trash", "require_confirm", opts, "ui.confirm", "trash", true)
2556

2657
-- 2023/01/15
2758
if type(opts.view) == "table" and opts.view.adaptive_size ~= nil then
@@ -35,13 +66,13 @@ local function refactored(opts)
3566
end
3667

3768
-- 2023/07/15
38-
utils.move_missing_val(opts, "", "sort_by", opts, "sort", "sorter", true)
69+
move(opts, "", "sort_by", opts, "sort", "sorter", true)
3970

4071
-- 2023/07/16
41-
utils.move_missing_val(opts, "git", "ignore", opts, "filters", "git_ignored", true)
72+
move(opts, "git", "ignore", opts, "filters", "git_ignored", true)
4273

4374
-- 2023/08/26
44-
utils.move_missing_val(opts, "renderer.icons", "webdev_colors", opts, "renderer.icons.web_devicons.file", "color", true)
75+
move(opts, "renderer.icons", "webdev_colors", opts, "renderer.icons.web_devicons.file", "color", true)
4576

4677
-- 2023/10/08
4778
if type(opts.renderer) == "table" and type(opts.renderer.highlight_diagnostics) == "boolean" then
@@ -59,7 +90,7 @@ local function refactored(opts)
5990
opts.update_focused_file.update_root = { enable = opts.update_focused_file.update_root }
6091
end
6192
end
62-
utils.move_missing_val(opts, "update_focused_file", "ignore_list", opts, "update_focused_file.update_root", "ignore_list", true)
93+
move(opts, "update_focused_file", "ignore_list", opts, "update_focused_file.update_root", "ignore_list", true)
6394

6495
-- 2025/04/30
6596
if opts.renderer and opts.renderer.icons and type(opts.renderer.icons.padding) == "string" then

lua/nvim-tree/utils.lua

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -377,38 +377,6 @@ function M.table_create_missing(tbl, path)
377377
return t
378378
end
379379

380-
--- Move a value from src to dst if value is nil on dst.
381-
--- Remove value from src
382-
---@param src table to copy from
383-
---@param src_path string dot separated string of sub-tables
384-
---@param src_pos string value pos
385-
---@param dst table to copy to
386-
---@param dst_path string dot separated string of sub-tables, created when missing
387-
---@param dst_pos string value pos
388-
---@param remove boolean
389-
function M.move_missing_val(src, src_path, src_pos, dst, dst_path, dst_pos, remove)
390-
for pos in string.gmatch(src_path, "([^%.]+)%.*") do
391-
if src[pos] and type(src[pos]) == "table" then
392-
src = src[pos]
393-
else
394-
return
395-
end
396-
end
397-
local src_val = src[src_pos]
398-
if src_val == nil then
399-
return
400-
end
401-
402-
dst = M.table_create_missing(dst, dst_path)
403-
if dst[dst_pos] == nil then
404-
dst[dst_pos] = src_val
405-
end
406-
407-
if remove then
408-
src[src_pos] = nil
409-
end
410-
end
411-
412380
local function round(value)
413381
-- Amount of digits to round to after floating point.
414382
local digits = 2

0 commit comments

Comments
 (0)