fix: Improvements

This commit is contained in:
Myzel394 2024-04-27 00:16:01 +02:00
parent d7e2125805
commit fbc1aa0424
No known key found for this signature in database
GPG Key ID: DEC4AAB876F73185

View File

@ -151,29 +151,25 @@ function M:insert_new_key(entries, keys, buffer)
end end
end end
vim.api.nvim_win_set_cursor(0, {entry.position.line_number, entry.position.value_start})
-- Hacky way to jump to end of object -- Hacky way to jump to end of object
vim.api.nvim_win_set_cursor(0, {entry.position.line_number, entry.position.value_start})
vim.cmd [[execute "normal %"]] vim.cmd [[execute "normal %"]]
local start_line = vim.api.nvim_win_get_cursor(0)[1] - 1 local start_line = vim.api.nvim_win_get_cursor(0)[1] - 1
-- Add comma to previous line -- Add comma to previous JSON entry
add_comma(buffer, start_line) add_comma(buffer, start_line)
--
-- Insert new lines -- Insert new lines
vim.api.nvim_buf_set_lines(buffer, start_line, start_line, false, writes) vim.api.nvim_buf_set_lines(buffer, start_line, start_line, false, writes)
--
-- -- -- Format lines -- Format lines
vim.api.nvim_win_set_cursor(0, {start_line, 1}) vim.api.nvim_win_set_cursor(0, {start_line, 1})
vim.cmd('execute "normal =' .. #writes .. 'j"') vim.cmd('execute "normal =' .. #writes .. 'j"')
--
-- -- Jump to the key -- Jump to the key
vim.api.nvim_win_set_cursor(0, {start_line + math.ceil(#writes / 2), 0}) vim.api.nvim_win_set_cursor(0, {start_line + math.ceil(#writes / 2), 0})
vim.cmd [[execute "normal $a"]] vim.cmd [[execute "normal $a"]]
-- vim.schedule(function()
-- vim.cmd [[%]]
-- end)
end end
return M; return M;