Skip to content

Select snacks picker element based on cursor position#458

Merged
stevearc merged 3 commits intostevearc:masterfrom
YosefBayoude:snacks-auto-place-cursor
Jun 1, 2025
Merged

Select snacks picker element based on cursor position#458
stevearc merged 3 commits intostevearc:masterfrom
YosefBayoude:snacks-auto-place-cursor

Conversation

@YosefBayoude
Copy link
Copy Markdown
Contributor

@YosefBayoude YosefBayoude commented Mar 30, 2025

When calling snacks picker, auto select the corresponding item, based on the cursor position on the buffer.
It's a small QOL imrpovement, that doesn't have much impact on usability, but provides quick info at a glance.

@github-actions github-actions bot requested a review from stevearc March 30, 2025 19:54
Comment on lines +64 to +66
local closest_or_exact_symbol = bufdata.positions[bufdata.last_win].exact_symbol or bufdata.positions[bufdata.last_win].closest_symbol
local currentIdx = closest_or_exact_symbol.idx
picker.list.cursor = currentIdx
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I'd prefer to do this the way we do for telescope, where we determine the selected index while iterating over symbols to build the list

local position = bufdata.positions[bufdata.last_win]
for _, item in bufdata:iter({ skip_hidden = false }) do
table.insert(results, item)
if item == position.closest_symbol then
default_selection_index = #results
end
end

Copy link
Copy Markdown
Contributor Author

@YosefBayoude YosefBayoude Apr 1, 2025

Choose a reason for hiding this comment

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

Made the requested changes, let me know what you think. Do note tho, setting the cursor happens on the on_show() call. Looking at the documentation and the code examples, I haven't found a way to set it at picker creation like Telescope does it. Any comment / information would ge helpful.

@github-actions github-actions bot requested a review from stevearc March 31, 2025 14:04
@stevearc
Copy link
Copy Markdown
Owner

stevearc commented Apr 6, 2025

Great, LGTM! Looks like one legit CI failure, the others should go away if you rebase master

Yosef BAYOUDE IZOUKA added 2 commits April 6, 2025 19:46
When calling snacks picker, auto select the corresponding item, based on
the cursor position on the buffer
@YosefBayoude YosefBayoude force-pushed the snacks-auto-place-cursor branch from 526dd49 to ba7bbe4 Compare April 6, 2025 17:46
@YosefBayoude
Copy link
Copy Markdown
Contributor Author

Oops, I'm not sure, I think my force push after the rebase messed up the flow 😅, could you please review again ? ty

@mehalter
Copy link
Copy Markdown
Contributor

mehalter commented Apr 10, 2025

@YosefBayoude it looks like you have a small type error as well as a formatting problem (just in case you didn't see the tests failed)

@YosefBayoude
Copy link
Copy Markdown
Contributor Author

Yes I did see it, haven't had time tho, will look into it over this weekend

@YosefBayoude
Copy link
Copy Markdown
Contributor Author

Could you please rerun the workflow to see if it conforms now ? Thanks

@stevearc
Copy link
Copy Markdown
Owner

stevearc commented Jun 1, 2025

LGTM thanks for the PR!

@stevearc stevearc merged commit 8c89f27 into stevearc:master Jun 1, 2025
1 check passed
@YosefBayoude YosefBayoude deleted the snacks-auto-place-cursor branch June 2, 2025 06:43
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.

3 participants