chore(#3196): move utils.table_create_missing to legacy

This commit is contained in:
Alexander Courtis 2025-09-08 11:09:45 +10:00
parent 748aff5d2c
commit 7bd381675b
2 changed files with 17 additions and 17 deletions

View File

@ -2,6 +2,22 @@ local notify = require("nvim-tree.notify")
local M = {}
--- Create empty sub-tables if not present
---@param tbl table to create empty inside of
---@param path string dot separated string of sub-tables
---@return table deepest sub-table
local function create(tbl, path)
local t = tbl
for s in string.gmatch(path, "([^%.]+)%.*") do
if t[s] == nil then
t[s] = {}
end
t = t[s]
end
return t
end
--- Move a value from src to dst if value is nil on dst.
--- Remove value from src
---@param src table to copy from
@ -24,7 +40,7 @@ local function move(src, src_path, src_pos, dst, dst_path, dst_pos, remove)
return
end
dst = M.table_create_missing(dst, dst_path)
dst = create(dst, dst_path)
if dst[dst_pos] == nil then
dst[dst_pos] = src_val
end

View File

@ -361,22 +361,6 @@ function M.escape_special_chars(path)
return M.is_windows and escape_special_char_for_windows(path) or path
end
--- Create empty sub-tables if not present
---@param tbl table to create empty inside of
---@param path string dot separated string of sub-tables
---@return table deepest sub-table
function M.table_create_missing(tbl, path)
local t = tbl
for s in string.gmatch(path, "([^%.]+)%.*") do
if t[s] == nil then
t[s] = {}
end
t = t[s]
end
return t
end
local function round(value)
-- Amount of digits to round to after floating point.
local digits = 2