Skip to content

Commit 4ce7c27

Browse files
committed
Revert "chore: remove repetitive code"
This reverts commit b97144c.
1 parent b108f54 commit 4ce7c27

File tree

1 file changed

+47
-11
lines changed

1 file changed

+47
-11
lines changed

filepicker/filepicker.go

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ import (
1717
)
1818

1919
var (
20-
lastID int
21-
idMtx sync.Mutex
20+
lastID int
21+
idMtx sync.Mutex
22+
2223
listWidth, listHeight, _ = term.GetSize(0)
2324
)
2425

@@ -135,9 +136,19 @@ func DefaultStylesWithRenderer(r *lipgloss.Renderer) Styles {
135136
Selected: r.NewStyle().Foreground(lipgloss.Color("212")).Bold(true),
136137
FileSize: r.NewStyle().Foreground(lipgloss.Color("240")).Width(fileSizeWidth).Align(lipgloss.Right),
137138
EmptyDirectory: r.NewStyle().Foreground(lipgloss.Color("240")).PaddingLeft(paddingLeft).SetString("Bummer. No Files Found."),
138-
SinglePaneStyle: r.NewStyle().MarginRight(2).Height(listHeight - 2).Width(listWidth - 2),
139-
LeftPaneStyle: r.NewStyle().MarginRight(2).Height(listHeight-2).Width(listWidth/2-2).Border(lipgloss.NormalBorder(), false, true, false, false),
140-
RightPaneStyle: r.NewStyle().MarginRight(2).Height(listHeight - 2).Width(listWidth/2 - 2),
139+
SinglePaneStyle: r.NewStyle().
140+
MarginRight(2).
141+
Height(listHeight - 2).
142+
Width(listWidth - 2),
143+
LeftPaneStyle: r.NewStyle().
144+
Border(lipgloss.NormalBorder(), false, true, false, false).
145+
MarginRight(2).
146+
Height(listHeight - 2).
147+
Width(listWidth/2 - 2),
148+
RightPaneStyle: r.NewStyle().
149+
MarginRight(2).
150+
Height(listHeight - 2).
151+
Width(listWidth/2 - 2),
141152
}
142153
}
143154

@@ -219,8 +230,25 @@ func (m Model) readDir(path string, showHidden bool) tea.Cmd {
219230
return errorMsg{err}
220231
}
221232

222-
sanitizedDirEntries := getCleanDirEntries(dirEntries, showHidden)
233+
sort.Slice(dirEntries, func(i, j int) bool {
234+
if dirEntries[i].IsDir() == dirEntries[j].IsDir() {
235+
return dirEntries[i].Name() < dirEntries[j].Name()
236+
}
237+
return dirEntries[i].IsDir()
238+
})
223239

240+
if showHidden {
241+
return readDirMsg{id: m.id, entries: dirEntries}
242+
}
243+
244+
var sanitizedDirEntries []os.DirEntry
245+
for _, dirEntry := range dirEntries {
246+
isHidden, _ := IsHidden(dirEntry.Name())
247+
if isHidden {
248+
continue
249+
}
250+
sanitizedDirEntries = append(sanitizedDirEntries, dirEntry)
251+
}
224252
return readDirMsg{id: m.id, entries: sanitizedDirEntries}
225253
}
226254
}
@@ -386,16 +414,24 @@ func (m Model) View() string {
386414
var s strings.Builder
387415
if m.selectedStack.Length() > 0 {
388416
if m.DualPane {
389-
rPane := m.Styles.EmptyDirectory.String()
390-
if len(m.files) > 0 {
391-
rPane = paneWriter(m)
417+
if len(m.files) == 0 {
418+
s.WriteString(lipgloss.JoinHorizontal(lipgloss.Top,
419+
m.Styles.LeftPaneStyle.Render(
420+
lPaneWriter(m.CurrentDirectory, m.Height),
421+
),
422+
m.Styles.RightPaneStyle.Render(
423+
m.Styles.EmptyDirectory.String(),
424+
),
425+
))
426+
return s.String()
392427
}
393-
394428
s.WriteString(lipgloss.JoinHorizontal(lipgloss.Top,
395429
m.Styles.LeftPaneStyle.Render(
396430
lPaneWriter(m.CurrentDirectory, m.Height),
397431
),
398-
m.Styles.RightPaneStyle.Render(rPane),
432+
m.Styles.RightPaneStyle.Render(
433+
paneWriter(m),
434+
),
399435
))
400436
return s.String()
401437
}

0 commit comments

Comments
 (0)