mirror of
https://github.com/Myzel394/jsonfly.nvim.git
synced 2025-06-18 04:05:26 +02:00
fix: Fix starting bracket missing on key insertion
This commit is contained in:
parent
85c097b59c
commit
49d5a258bc
@ -23,11 +23,11 @@ end
|
|||||||
---@return boolean - Whether the line contains an empty JSON object
|
---@return boolean - Whether the line contains an empty JSON object
|
||||||
local function line_contains_empty_json(line, also_match_end_bracket)
|
local function line_contains_empty_json(line, also_match_end_bracket)
|
||||||
-- Starting and ending on same line
|
-- Starting and ending on same line
|
||||||
return string.match(line, ".*[%{%[]%s*[%]%]]%s*,?*%s*")
|
return string.match(line, ".*[%{%[]%s*[%}%]]%s*,?*%s*")
|
||||||
-- Opening bracket on line
|
-- Opening bracket on line
|
||||||
or string.match(line, ".*[%{%[]%s*")
|
or string.match(line, ".*[%{%[]%s*")
|
||||||
-- Closing bracket on line
|
-- Closing bracket on line
|
||||||
or (also_match_end_bracket and string.match(line, ".*.*[%]%}]%s*,?%s*"))
|
or (also_match_end_bracket and string.match(line, ".*.*[%}%]]%s*,?%s*"))
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param entry Entry
|
---@param entry Entry
|
||||||
@ -88,9 +88,9 @@ local function write_keys(keys, index, lines)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if key.type == "object_wrapper" and #lines > 0 then
|
if key.type == "object_wrapper" then
|
||||||
local previous_line = lines[#lines] or ""
|
local previous_line = lines[#lines] or ""
|
||||||
if line_contains_empty_json(previous_line, true) then
|
if line_contains_empty_json(previous_line, true) or #lines == 0 then
|
||||||
lines[#lines + 1] = "{"
|
lines[#lines + 1] = "{"
|
||||||
else
|
else
|
||||||
lines[#lines] = previous_line .. " {"
|
lines[#lines] = previous_line .. " {"
|
||||||
@ -106,7 +106,7 @@ local function write_keys(keys, index, lines)
|
|||||||
elseif key.type == "array_wrapper" then
|
elseif key.type == "array_wrapper" then
|
||||||
local previous_line = lines[#lines] or ""
|
local previous_line = lines[#lines] or ""
|
||||||
-- Starting and ending on same line
|
-- Starting and ending on same line
|
||||||
if line_contains_empty_json(previous_line, true) then
|
if line_contains_empty_json(previous_line, true) or #lines == 0 then
|
||||||
lines[#lines + 1] = "["
|
lines[#lines + 1] = "["
|
||||||
else
|
else
|
||||||
lines[#lines] = previous_line .. " ["
|
lines[#lines] = previous_line .. " ["
|
||||||
@ -300,8 +300,6 @@ function M:insert_new_key(entries, keys, buffer)
|
|||||||
normalize_array_indexes(entries, starting_keys, remaining_keys[1])
|
normalize_array_indexes(entries, starting_keys, remaining_keys[1])
|
||||||
end
|
end
|
||||||
|
|
||||||
-- normalize_array_indexes(remaining_keys)
|
|
||||||
|
|
||||||
local _writes = {}
|
local _writes = {}
|
||||||
write_keys(remaining_keys, 1, _writes)
|
write_keys(remaining_keys, 1, _writes)
|
||||||
local writes = {}
|
local writes = {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user