Skip to content

Commit cce3805

Browse files
committed
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.
1 parent 4382fdf commit cce3805

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

filepicker/filepicker.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func New() Model {
5050
maxStack: newStack(),
5151
KeyMap: DefaultKeyMap(),
5252
Styles: DefaultStyles(),
53+
FileSelected: "",
5354
}
5455
}
5556

@@ -247,8 +248,18 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
247248
if msg.id != m.id {
248249
break
249250
}
251+
if m.FileSelected != "" {
252+
for i, f := range msg.entries {
253+
if f.Name() == m.FileSelected {
254+
m.selected = i
255+
m.FileSelected = ""
256+
257+
break
258+
}
259+
}
260+
}
250261
m.files = msg.entries
251-
m.max = max(m.max, m.Height-1)
262+
m.max = max(m.Height-1, m.max)
252263
case tea.WindowSizeMsg:
253264
if m.AutoHeight {
254265
m.Height = msg.Height - marginBottom

0 commit comments

Comments
 (0)