bubbles
bubbles copied to clipboard
feat(filepicker): add file selection persistence
- Introduced
FileSelectedfield toModelto store the selected file name. - Updated
Updatemethod to restore the selected file index based onFileSelected. - Adjusted min and max values to ensure the selected file is within the visible range.
Ex.
fp := filepicker.New()
fp.AllowedTypes = []string{".mod", ".sum", ".go", ".txt", ".md"}
fp.CurrentDirectory, _ = os.Getwd()
fp.FileSelected = "main.go"
Hey @CoMfUcIoS you can do this with the current API, though we manage the persisted state through the model that owns the filepicker. Is there any reason the implementation in this PR might be preferable to the existing way of doing this?
Here's a working example of what I'm talking about: https://github.com/charmbracelet/bubbletea/blob/main/examples/file-picker/main.go
At the point of raising this PR there wasnt a way to do it (as far as i remember :)). If it is now there then this makes this PR redundant, hence closing.