-
-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add string array support to open_mapping
setting.
#557
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sbkkalex thanks for this PR, happy to have this more flexible to accommodate other folks 👍🏾, I've just made a few comments mainly around typos and the duplication
README.md
Outdated
@@ -126,7 +126,7 @@ I'm also going to be pretty conservative about what I add. | |||
|
|||
This plugin must be explicitly enabled by using `require("toggleterm").setup{}` | |||
|
|||
Setting the `open_mapping` key to use for toggling the terminal(s) will set up mappings for _normal_ mode. | |||
Setting the `open_mapping` key to use for toggling the terminal(s) will set up mappings for _normal_ mode. The `open_mappint` can be a key string or an array of key strings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting the `open_mapping` key to use for toggling the terminal(s) will set up mappings for _normal_ mode. The `open_mappint` can be a key string or an array of key strings. | |
Setting the `open_mapping` key to use for toggling the terminal(s) will set up mappings for _normal_ mode. The `open_mapping` can be a key string or an array of key strings. |
doc/toggleterm.txt
Outdated
last toggled terminal will be opened. In case there are multiple terminals | ||
opened they’ll all be closed, and on the next mapping key they’ll be | ||
restored. | ||
mappings for _normal_ mode. The `open_mappint` can be a key string or an array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mappings for _normal_ mode. The `open_mappint` can be a key string or an array | |
mappings for _normal_ mode. The `open_mapping` can be a key string or an array |
lua/toggleterm.lua
Outdated
|
||
-- Key mapping function | ||
---@param key string | ||
local map = function(key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the style
local map = function(key) | |
local function map(key) |
lua/toggleterm.lua
Outdated
desc = "Toggle Terminal", | ||
silent = true, | ||
}) | ||
end | ||
end | ||
|
||
if type(mapping) == "string" then map(mapping) end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although it's impossible (🤞🏾) I'd rather this was an if then else if
I feel uncomfortable with the idea that it could possible fall into the next clause even though it can't
lua/toggleterm/terminal.lua
Outdated
|
||
-- Key mapping function | ||
---@param key string | ||
local map = function(key) | ||
vim.keymap.set("t", key, "<Cmd>ToggleTerm<CR>", { buffer = bufnr, silent = true }) | ||
end | ||
|
||
if config.terminal_mappings then | ||
if type(mapping) == "string" then map(mapping) end | ||
if type(mapping) == "table" then | ||
for _, key in pairs(mapping) do | ||
map(key) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks to me like this logic is just being repeated maybe it's best to do this once in utils.lua
generically and use that helper function in both of the places you've made this change
@akinsho |
I sometime use a Japanese keyboard, and it don't have the
\
key, instead it have a¥
key.It would be helpful for people like me who what to bind multiple keys for toggle terminal. So I modified the
open_mapping
setting to also take an array of string as parameter.