Skip to content

get highlighted DirEntry in filepicker #580

Open
@mJehanno

Description

@mJehanno

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions