Skip to content

Commit

Permalink
fix: ensure on_choice operates on exact items element (#566)
Browse files Browse the repository at this point in the history
As `on_choice()` actions depend on modifying terminal objects in place,
make sure to operate on exact element and not a copy. As users can
override `vim.ui.select()`, its implementation might return an item's
copy (which is not explicitly prohibited) making later `on_choice()`
actions not 100% full proof.
  • Loading branch information
echasnovski authored Apr 19, 2024
1 parent f20e809 commit d3fff44
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lua/toggleterm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@ local function select_terminal(opts)
vim.ui.select(terminals, {
prompt = "Please select a terminal to open (or focus): ",
format_item = function(term) return term.id .. ": " .. term:_display_name() end,
}, function(term)
}, function(_, idx)
local term = terminals[idx]
if not term then return end
if term:is_open() then
term:focus()
Expand Down

0 comments on commit d3fff44

Please # to comment.