bubbles icon indicating copy to clipboard operation
bubbles copied to clipboard

feat(filepicker): add file selection persistence

Open CoMfUcIoS opened this issue 1 year ago • 1 comments

  • Introduced FileSelected field to Model to store the selected file name.
  • Updated Update method to restore the selected file index based on FileSelected.
  • 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"

CoMfUcIoS avatar Sep 30 '24 16:09 CoMfUcIoS

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

bashbunni avatar Jan 23 '25 01:01 bashbunni

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.

CoMfUcIoS avatar Sep 13 '25 08:09 CoMfUcIoS