From cce3805c4d083ef6b719503cc429aa54cf3538ba Mon Sep 17 00:00:00 2001 From: Ioannis Karasavvaidis Date: Mon, 30 Sep 2024 17:17:22 +0100 Subject: [PATCH] feat(filepicker): add file selection persistence - 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. --- filepicker/filepicker.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/filepicker/filepicker.go b/filepicker/filepicker.go index 2288a5d2..a1ced1a0 100644 --- a/filepicker/filepicker.go +++ b/filepicker/filepicker.go @@ -50,6 +50,7 @@ func New() Model { maxStack: newStack(), KeyMap: DefaultKeyMap(), Styles: DefaultStyles(), + FileSelected: "", } } @@ -247,8 +248,18 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { if msg.id != m.id { break } + if m.FileSelected != "" { + for i, f := range msg.entries { + if f.Name() == m.FileSelected { + m.selected = i + m.FileSelected = "" + + break + } + } + } m.files = msg.entries - m.max = max(m.max, m.Height-1) + m.max = max(m.Height-1, m.max) case tea.WindowSizeMsg: if m.AutoHeight { m.Height = msg.Height - marginBottom