From 374d4af609767f62fbd9dc08df500e49217bbe88 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Tue, 14 May 2024 09:32:38 +0000 Subject: [PATCH 1/2] feat: Updated 1 files --- lua/hurl/main.lua | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/lua/hurl/main.lua b/lua/hurl/main.lua index 83f93b9..dca3228 100644 --- a/lua/hurl/main.lua +++ b/lua/hurl/main.lua @@ -485,14 +485,12 @@ function M.setup() "Press 'q' to close, 'e' to edit, or 'n' to create a variable." ) - -- Add e key binding to edit the variable + -- Add e key binding to edit the variable inline in the buffer text_popup:map('n', 'e', function() local line = vim.api.nvim_get_current_line() local var_name = line:match('^(.-) =') if var_name then - local new_value = vim.fn.input('Enter new value for ' .. var_name .. ': ') - _HURL_GLOBAL_CONFIG.global_vars[var_name] = new_value - vim.api.nvim_set_current_line(var_name .. ' = ' .. new_value) + vim.api.nvim_input('A') end end) @@ -520,10 +518,24 @@ function M.setup() vim.cmd('HurlSetVariable ' .. var_name .. ' ' .. var_value) -- Append to the last line vim.api.nvim_buf_set_lines(0, line_position, -1, false, { var_name .. ' = ' .. var_value }) + + -- Refresh the buffer display + vim.api.nvim_buf_set_lines(0, 0, -1, false, vim.tbl_map(function(key) + return key .. ' = ' .. _HURL_GLOBAL_CONFIG.global_vars[key] + end, vim.tbl_keys(_HURL_GLOBAL_CONFIG.global_vars))) end) end, { nargs = '*', range = true, + on_write = function() + local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false) + for _, line in ipairs(lines) do + local var_name, var_value = line:match('^(.-) = (.+)$') + if var_name and var_value then + _HURL_GLOBAL_CONFIG.global_vars[var_name] = var_value + end + end + end, }) -- Show debug info @@ -536,6 +548,15 @@ function M.setup() end, { nargs = '*', range = true, + on_write = function() + local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false) + for _, line in ipairs(lines) do + local var_name, var_value = line:match('^(.-) = (.+)$') + if var_name and var_value then + _HURL_GLOBAL_CONFIG.global_vars[var_name] = var_value + end + end + end, }) -- TODO: Keep last 10 requests and add key binding to navigate through them @@ -546,6 +567,15 @@ function M.setup() end, { nargs = '*', range = true, + on_write = function() + local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false) + for _, line in ipairs(lines) do + local var_name, var_value = line:match('^(.-) = (.+)$') + if var_name and var_value then + _HURL_GLOBAL_CONFIG.global_vars[var_name] = var_value + end + end + end, }) end From a7f4270ff1d8c66cca50de4064b8617b681f79c1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 14 May 2024 09:33:10 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- lua/hurl/main.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lua/hurl/main.lua b/lua/hurl/main.lua index dca3228..d4e6e98 100644 --- a/lua/hurl/main.lua +++ b/lua/hurl/main.lua @@ -518,11 +518,17 @@ function M.setup() vim.cmd('HurlSetVariable ' .. var_name .. ' ' .. var_value) -- Append to the last line vim.api.nvim_buf_set_lines(0, line_position, -1, false, { var_name .. ' = ' .. var_value }) - + -- Refresh the buffer display - vim.api.nvim_buf_set_lines(0, 0, -1, false, vim.tbl_map(function(key) - return key .. ' = ' .. _HURL_GLOBAL_CONFIG.global_vars[key] - end, vim.tbl_keys(_HURL_GLOBAL_CONFIG.global_vars))) + vim.api.nvim_buf_set_lines( + 0, + 0, + -1, + false, + vim.tbl_map(function(key) + return key .. ' = ' .. _HURL_GLOBAL_CONFIG.global_vars[key] + end, vim.tbl_keys(_HURL_GLOBAL_CONFIG.global_vars)) + ) end) end, { nargs = '*',