Skip to content

support WithPreselected option #243

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

Merged
merged 1 commit into from
Apr 15, 2025
Merged

support WithPreselected option #243

merged 1 commit into from
Apr 15, 2025

Conversation

ktr0731
Copy link
Owner

@ktr0731 ktr0731 commented Apr 15, 2025

WithPreselected option introduces a new feature for preselecting items. If the option is called with Find, the cursor is positioned on the first item that returns true.

// Single selection mode
// The cursor will be positioned on the first item that matches the predicate
idx, err := fuzzyfinder.Find(
    tracks,
    func(i int) string {
        return tracks[i].Name
    },
    fuzzyfinder.WithPreselected(func(i int) bool {
        return tracks[i].Name == "bar"
    }),
)

// Multi selection mode
// All items that match the predicate will be selected initially
idxs, err := fuzzyfinder.FindMulti(
    tracks,
    func(i int) string {
        return tracks[i].Name
    },
    fuzzyfinder.WithPreselected(func(i int) bool {
        return tracks[i].Artist == "artist2"
    }),
)

@ktr0731 ktr0731 requested a review from Copilot April 15, 2025 05:08
@ktr0731 ktr0731 self-assigned this Apr 15, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 6 out of 8 changed files in this pull request and generated no comments.

Files not reviewed (2)
  • example/go.mod: Language not supported
  • go.mod: Language not supported
Comments suppressed due to low confidence (1)

fuzzyfinder.go:143

  • The use of opt.beginAtTop in this condition appears contradictory, as it sets the cursor to the last item rather than the top. Confirm whether the intended behavior is to position the cursor at index 0 (top) when opt.beginAtTop is true.
if !cursorPositioned && opt.beginAtTop {

Copy link

codecov bot commented Apr 15, 2025

Codecov Report

Attention: Patch coverage is 34.09091% with 29 lines in your changes missing coverage. Please review.

Project coverage is 85.07%. Comparing base (2825517) to head (4de0a78).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #243      +/-   ##
==========================================
- Coverage   87.68%   85.07%   -2.62%     
==========================================
  Files           5        5              
  Lines         869      911      +42     
==========================================
+ Hits          762      775      +13     
- Misses         94      119      +25     
- Partials       13       17       +4     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ktr0731 ktr0731 merged commit a4a4a57 into master Apr 15, 2025
8 checks passed
@ktr0731 ktr0731 deleted the preselected branch April 15, 2025 05:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant