Skip to content
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

get highlighted DirEntry in filepicker #580

Open
mJehanno opened this issue Aug 13, 2024 · 0 comments
Open

get highlighted DirEntry in filepicker #580

mJehanno opened this issue Aug 13, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@mJehanno
Copy link

Is your feature request related to a problem? Please describe.
I'd like to get the DirEntry that is currently highlighted by the user (ie: on which items the cursor currently is).
The name would not be enough as I want to do something if it's a directory and another thing if it's a file

Describe the solution you'd like
A method on the filepicker bubble that would return the current dirEntry.
Smething probaby close to this :

func (m Model) GetCurrentFile() fs.DirEntry {
	if m.selected < len(m.files) {
		return m.files[m.selected]
	}
	return nil
}

Describe alternatives you've considered
create my own bubble by copy/pasting the code of the filepicker.

Additional context
the hardest part might be on how to use this kind of method because this kind of call would be done in an Update(msg tea.Msg) method, when the cursor might change from user input. So the function above could take a modifier as an argument ie :

func (m Model) GetCurrentFile(modifier int) fs.DirEntry {
	newCursor := m.selected + modifier
        if newCursor < len(m.files) {
		return m.files[newCursor]
	}
	return nil
}
@mJehanno mJehanno added the enhancement New feature or request label Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant