chore(#3196): move utils.table_create_missing to legacy
This commit is contained in:
parent
748aff5d2c
commit
7bd381675b
@ -2,6 +2,22 @@ local notify = require("nvim-tree.notify")
|
|||||||
|
|
||||||
local M = {}
|
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.
|
--- Move a value from src to dst if value is nil on dst.
|
||||||
--- Remove value from src
|
--- Remove value from src
|
||||||
---@param src table to copy from
|
---@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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
dst = M.table_create_missing(dst, dst_path)
|
dst = create(dst, dst_path)
|
||||||
if dst[dst_pos] == nil then
|
if dst[dst_pos] == nil then
|
||||||
dst[dst_pos] = src_val
|
dst[dst_pos] = src_val
|
||||||
end
|
end
|
||||||
|
|||||||
@ -361,22 +361,6 @@ function M.escape_special_chars(path)
|
|||||||
return M.is_windows and escape_special_char_for_windows(path) or path
|
return M.is_windows and escape_special_char_for_windows(path) or path
|
||||||
end
|
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)
|
local function round(value)
|
||||||
-- Amount of digits to round to after floating point.
|
-- Amount of digits to round to after floating point.
|
||||||
local digits = 2
|
local digits = 2
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user