Commit graph

6 commits

Author SHA1 Message Date
Steven Arcangeli
4c3bfa29f3
fix(picker): vim.ui.select callback is called when canceling selection (#1115)
## Description

From the docs on `:help vim.ui.select`
```
      • {on_choice}  (`fun(item: any?, idx: integer?)`) Called once the user
                     made a choice. `idx` is the 1-based index of `item`
                     within `items`. `nil` if the user aborted the dialog.
```

Right now the behavior will call `on_choice` if the user confirmed a
selection, but will not be called at all if the user explicitly or
implicitly closes the picker. As a plugin author, I rely on the
guarantee that if I call `vim.ui.select`, the callback _will_ be called
either with a value or with a nil.

I just added the simplest, dumbest possible fix for this that prevents
double-calling the callback.

## Related Issue(s)

N/A

## Screenshots

N/A
2025-02-13 17:52:20 +01:00
Folke Lemaitre
c667622fb7
fix(picker.select): default height shows just the items. See #902 2025-02-03 20:51:04 +01:00
Folke Lemaitre
d70af2d253
fix(picker.select): allow configuring vim.ui.select with the select source. Closes #776 2025-01-29 12:49:20 +01:00
Folke Lemaitre
9986b47707
fix(picker.config): better config merging and tests 2025-01-17 20:36:33 +01:00
Folke Lemaitre
076259d263
fix(picker.select): allow main to be current. Fixes #497 2025-01-15 17:35:45 +01:00
Folke Lemaitre
559d6c6bf2
feat(snacks): added snacks.picker (#445)
## Description

More info coming tomorrow.

In short:
- very fast. pretty much realtime filtering/sorting in huge repos (like
1.7 million files)
- extensible
- easy to customize the layout (and lots of presets) with
`snacks.layout`
- simple to create custom pickers
- `vim.ui.select`
- lots of builtin pickers
- uses treesitter highlighting wherever it makes sense
- fast lua fuzzy matcher which supports the [fzf
syntax](https://junegunn.github.io/fzf/search-syntax/) and additionally
supports field filters, like `file:lua$ 'function`

There's no snacks picker command, just use lua.

```lua
-- all pickers
Snacks.picker()

-- run files picker
Snacks.picker.files(opts)
Snacks.picker.pick("files", opts)
Snacks.picker.pick({source = "files", ...})
```

<!-- Describe the big picture of your changes to communicate to the
maintainers
  why we should accept this pull request. -->

## Todo
- [x] issue with preview loc not always correct when scrolling fast in
list (probably due to `snacks.scroll`)
- [x] `grep` (`live_grep`) is sometimes too fast in large repos and can
impact ui rendering. Not very noticeable, but something I want to look
at.
- [x] docs
- [x] treesitter highlights are broken. Messed something up somewhere

## Related Issue(s)

<!--
  If this PR fixes any issues, please link to the issue here.
  - Fixes #<issue_number>
-->

## Screenshots

<!-- Add screenshots of the changes if applicable. -->
2025-01-14 22:53:59 +01:00