Skip to content

Commit

Permalink
fix: telescope errors when exiting with no preview
Browse files Browse the repository at this point in the history
  • Loading branch information
gsuuon committed May 23, 2024
1 parent f623d61 commit 57a7d3b
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions lua/telescope/_extensions/model.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ local function entry_maker(bufnr)
display = display .. ' [' .. tostring(#chat_buf.contents.messages) .. ']'

return {
value = bufnr,
value = display,
display = display,
ordinal = bufnr,
bufnr = bufnr,
}
end

Expand All @@ -43,16 +44,20 @@ local function create_bare_buffer_previewer(title)
if self.state and self.state.winid then
-- https://github.com/nvim-telescope/telescope.nvim/blob/0c12735d5aff6a48ffd8111bf144dc2ff44e5975/lua/telescope/previewers/buffer_previewer.lua#L396
-- push a new empty buffer because telescope deletes the last buffer
local bufnr = vim.api.nvim_create_buf(false, true)
utils.win_set_buf_noautocmd(self.state.winid, bufnr)
if vim.api.nvim_win_is_valid(self.state.winid) then -- can become invalid somehow
local bufnr = vim.api.nvim_create_buf(false, true)
utils.win_set_buf_noautocmd(self.state.winid, bufnr)
end
end
end,
preview_fn = function(self, entry, status)
local preview_winid = status.layout.preview
and status.layout.preview.winid

vim.api.nvim_win_set_buf(preview_winid, entry.value)
self.state.winid = preview_winid
if vim.api.nvim_win_is_valid(preview_winid) then
vim.api.nvim_win_set_buf(preview_winid, entry.bufnr)
self.state.winid = preview_winid
end
end,
title = title,
})
Expand All @@ -68,15 +73,11 @@ local function mchat(opts)
results = get_mchat_buffers(),
entry_maker = entry_maker,
}),
-- TODO the prompt doesn't actually filter the entries but I have no idea how to make telescope do that
-- there doesn't seem to be a place to plug in a function to just filter the entries based on prompt
-- is it part of the finder? sorter?
-- currently the prompt seems to filter results by the initial results (so the buffer number)
sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
local selection = action_state.get_selected_entry()
vim.api.nvim_set_current_buf(selection.value)
end)
return true
end,
previewer = create_bare_buffer_previewer('model.nvim mchat buffers'),
})
:find()
Expand Down

0 comments on commit 57a7d3b

Please sign in to comment.