Repository navigation
fix: make pickers work with async vim.ui.select - #60
Merged
Merged
Conversation
`selecttemplate` can run from a FileType autocmd fired inside filetype detection's `vim._with` context. That context restores the previous window on return, which takes focus away from asynchronous `vim.ui.select` implementations such as telescope-ui-select: the picker stays on screen while keystrokes go to the file buffer. Open the picker with `vim.schedule` so it runs after the context is restored. Capture the requesting buffer and write the chosen template into it with `nvim_buf_call`, so the write and wildcard expansion target that buffer regardless of which buffer is current when the choice arrives. If the buffer was closed in the meantime, warn and write nothing. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
`create_template` checked each answer on the line after its `vim.ui.select`/`vim.ui.input` call, which only works when the prompt returns after the user answers. With asynchronous implementations such as telescope-ui-select, the command printed "Exiting template creation!" immediately and the open picker had no effect. Each question is now asked from the previous answer's callback, and cancelling any prompt stops without creating anything. The "current buffer" source is copied with `writefile` from the originating buffer, and the trigger default is read from that buffer. Choosing "empty buffer" no longer fails with E484 on a temp file that was never written. On success, the message points to the template directory where the new buffer should be saved. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Template selection and
:EsqueletoNewassumedvim.ui.selectreturns onlyafter the user answers, as the built-in
inputlist()does. Asynchronousimplementations such as telescope-ui-select return right away, which broke
both.
Template selection (
core.lua): the picker opened from aFileTypeautocmd that runs inside filetype detection's
vim._withcontext. When thatcontext restored the previous window, focus left the picker, so it stayed on
screen while keystrokes went to the file buffer. The picker now opens via
vim.schedule, and the chosen template is written into the buffer thatrequested it.
:EsqueletoNew(excmd.lua): each answer was checked on the line afterits prompt, so with an asynchronous picker the command printed "Exiting
template creation!" immediately. Each question is now asked from the
previous answer's callback. This also fixes an E484 error when choosing
"empty buffer", which happened with any picker.
Testing
tests/select_spec.luaandtests/excmd_spec.luastubvim.ui.select/vim.ui.inputwith prompts that return before and afterthe answer. Six of the seven fail on
main; the remaining one(cancelling the first
:EsqueletoNewprompt) passes on both.make test_local: 24 passed.file (via
:eand at startup) and stepping through:EsqueletoNew.🤖 Generated with Claude Code