Skip to content

Commit

Permalink
Add possibility to customize request view mappings (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
yngwi authored Aug 1, 2024
1 parent 0143872 commit 30c52d7
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ Add the following configuration to your Neovim setup with [lazy.nvim](https://gi
'-q',
},
},
-- Default mappings for the response popup or split views
mappings = {
close = 'q', -- Close the response popup or split view
next_panel = '<C-n>', -- Move to the next response popup window
prev_panel = '<C-p>', -- Move to the previous response popup window
},
},
keys = {
-- Run API request
Expand Down
19 changes: 18 additions & 1 deletion doc/hurl.nvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ Add the following configuration to your Neovim setup with lazy.nvim
'-q',
},
},
-- Default mappings for the response popup or split views
mappings = {
close = 'q', -- Close the response popup or split view
next_panel = '<C-n>', -- Move to the next response popup window
prev_panel = '<C-p>', -- Move to the previous response popup window
},
},
keys = {
-- Run API request
Expand Down Expand Up @@ -337,13 +343,16 @@ DEFAULT KEY MAPPINGS *hurl.nvim-default-key-mappings*

`hurl.nvim` comes with some default key mappings to streamline your workflow:

- `q`: Close the current popup window.
- `q`: Close the current popup window or split.
- `<C-n>`: Switch to the next popup window.
- `<C-p>`: Switch to the previous popup window.

These key mappings are active within the popup windows that `hurl.nvim`
displays.

The mappings can be customized in the configuration table passed to the setup
function.


CONFIGURATION *hurl.nvim-configuration*

Expand Down Expand Up @@ -396,6 +405,11 @@ CONFIGURATION *hurl.nvim-configuration*
'-q',
},
},
mappings = {
close = 'q',
next_panel = '<C-n>',
prev_panel = '<C-p>',
},
}
<

Expand All @@ -420,6 +434,9 @@ To apply these configurations, include them in your Neovim setup like this:
'-q',
},
},
mappings = {
close = '<C-c>',
},
})
<

Expand Down
8 changes: 7 additions & 1 deletion lua/hurl/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ local default_config = {
'-q',
},
},
-- Default mappings for the response popup or split views
mappings = {
close = 'q', -- Close the response popup or split view
next_panel = '<C-n>', -- Move to the next response popup window
prev_panel = '<C-p>', -- Move to the previous response popup window
},
}
--- Global configuration for entire plugin, easy to access from anywhere
_HURL_GLOBAL_CONFIG = default_config
Expand All @@ -60,7 +66,7 @@ function M.setup(options)
options.env_file = { options.env_file }
end

_HURL_GLOBAL_CONFIG = vim.tbl_extend('force', _HURL_GLOBAL_CONFIG, options or default_config)
_HURL_GLOBAL_CONFIG = vim.tbl_deep_extend('force', _HURL_GLOBAL_CONFIG, options or default_config)

require('hurl.main').setup()
end
Expand Down
12 changes: 6 additions & 6 deletions lua/hurl/popup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,25 @@ M.show = function(data, type)
end

-- Map q to quit
popups.top:map('n', 'q', function()
popups.top:map('n', _HURL_GLOBAL_CONFIG.mappings.close, function()
quit()
end)
popups.bottom:map('n', 'q', function()
popups.bottom:map('n', _HURL_GLOBAL_CONFIG.mappings.close, function()
quit()
end)

-- Map <Ctr-n> to next popup
popups.top:map('n', '<C-n>', function()
popups.top:map('n', _HURL_GLOBAL_CONFIG.mappings.next_panel, function()
vim.api.nvim_set_current_win(popups.bottom.winid)
end)
popups.bottom:map('n', '<C-n>', function()
popups.bottom:map('n', _HURL_GLOBAL_CONFIG.mappings.next_panel, function()
vim.api.nvim_set_current_win(popups.top.winid)
end)
-- Map <Ctr-p> to previous popup
popups.top:map('n', '<C-p>', function()
popups.top:map('n', _HURL_GLOBAL_CONFIG.mappings.prev_panel, function()
vim.api.nvim_set_current_win(popups.bottom.winid)
end)
popups.bottom:map('n', '<C-p>', function()
popups.bottom:map('n', _HURL_GLOBAL_CONFIG.mappings.prev_panel, function()
vim.api.nvim_set_current_win(popups.top.winid)
end)

Expand Down
2 changes: 1 addition & 1 deletion lua/hurl/split.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ M.show = function(data, type)
vim.cmd('q')
split:unmount()
end
split:map('n', 'q', function()
split:map('n', _HURL_GLOBAL_CONFIG.mappings.close, function()
quit()
end)
end
Expand Down

0 comments on commit 30c52d7

Please sign in to comment.