Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ func (m Model) startFuzzyFind() (tea.Model, tea.Cmd) {

func (m Model) startView() (tea.Model, tea.Cmd) {
e := m.activePanel().CurrentEntry()
if e == nil || e.IsDir() {
if e == nil || e.IsDir() || m.activePanel().IsSymlinkToDir(e) {
return m, nil
}
if !m.activePanel().IsLocal() {
Expand All @@ -1047,7 +1047,7 @@ func (m Model) startView() (tea.Model, tea.Cmd) {

func (m Model) startEdit() (tea.Model, tea.Cmd) {
e := m.activePanel().CurrentEntry()
if e == nil || e.IsDir() {
if e == nil || e.IsDir() || m.activePanel().IsSymlinkToDir(e) {
return m, nil
}
if !m.activePanel().IsLocal() {
Expand Down Expand Up @@ -1297,7 +1297,7 @@ func (m *Model) syncQuickView() tea.Cmd {
return nil
}
entry := p.CurrentEntry()
isDir := entry != nil && entry.IsDir()
isDir := entry != nil && (entry.IsDir() || p.IsSymlinkToDir(entry))
// Archive entries have no readable stream; local and remote both do.
available := p.Location().Kind != vfs.KindArchive
// A remote file comes back as a quickview.FileLoadedMsg.
Expand Down
24 changes: 19 additions & 5 deletions internal/ui/panel/panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,20 @@ func (m Model) InArchive() bool {
return m.Location().Kind == vfs.KindArchive
}

// IsSymlinkToDir returns whether e is a symlink that resolves to a directory.
func (m Model) IsSymlinkToDir(e fs.DirEntry) bool {
if m.InArchive() || e.Type()&fs.ModeSymlink == 0 {
return false
}
info, err := m.Location().FS.Stat(m.CurrentPath())
return err == nil && info.IsDir()
}

// IsDirLike reports whether e behaves like a directory (real dir or symlink-to-dir).
func IsDirLike(m *Model, e fs.DirEntry) bool {
return e.IsDir() || m.IsSymlinkToDir(e)
}

// LocationLabel is the display string for a nested location, or "".
func (m Model) LocationLabel() string {
return m.Location().Label
Expand Down Expand Up @@ -277,7 +291,7 @@ func (m *Model) HandleDirLoaded(msg DirLoadedMsg) {
all = append(all, e)
}

SortEntries(all, m.sortMode)
SortEntries(all, m.sortMode, func(e fs.DirEntry) bool { return IsDirLike(m, e) })
m.entries = all

// Cache FileInfo
Expand Down Expand Up @@ -442,7 +456,7 @@ func (m *Model) handleEnter() tea.Cmd {
if e == nil {
return nil
}
if e.IsDir() {
if e.IsDir() || m.IsSymlinkToDir(e) {
return m.enterDir()
}

Expand All @@ -466,7 +480,7 @@ func (m *Model) handleEnter() tea.Cmd {

func (m *Model) handleSpace() tea.Cmd {
e := m.CurrentEntry()
if e == nil || e.IsDir() || !m.IsLocal() {
if e == nil || IsDirLike(m, e) || !m.IsLocal() {
return nil
}
// Space on file = preview
Expand Down Expand Up @@ -496,7 +510,7 @@ func (m *Model) enterDir() tea.Cmd {
if e == nil {
return nil
}
if !e.IsDir() {
if !e.IsDir() && !m.IsSymlinkToDir(e) {
return nil
}
if e.Name() == ".." {
Expand Down Expand Up @@ -624,7 +638,7 @@ func (m *Model) InvertSelection() {
// ChangeSortMode cycles to the next sort mode and re-sorts.
func (m *Model) ChangeSortMode() {
m.sortMode = (m.sortMode + 1) % 4
SortEntries(m.entries, m.sortMode)
SortEntries(m.entries, m.sortMode, func(e fs.DirEntry) bool { return IsDirLike(m, e) })
}

// parentEntry is a synthetic ".." directory entry.
Expand Down
40 changes: 40 additions & 0 deletions internal/ui/panel/panel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,43 @@ func (e *nameOnlyEntry) IsDir() bool { return e.isDir }
func (e *nameOnlyEntry) Type() fs.FileMode { return 0 }
func (e *nameOnlyEntry) Info() (fs.FileInfo, error) { return nil, nil }
func (e *nameOnlyEntry) String() string { return e.name }

// symlinkToDirEntry is a minimal fs.DirEntry that behaves like a directory but
// reports IsDir=false (same as os.ReadDir on a symlink-to-dir).
type symlinkToDirEntry struct {
nameOnlyEntry
}

func (e *symlinkToDirEntry) Type() fs.FileMode { return fs.ModeSymlink }

func TestSortEntriesSymlinkGroupsWithDirs(t *testing.T) {
entries := []fs.DirEntry{
&nameOnlyEntry{name: "b.txt", isDir: false},
&nameOnlyEntry{name: "a.txt", isDir: false},
&symlinkToDirEntry{nameOnlyEntry{name: "d-link"}},
&nameOnlyEntry{name: "c.txt", isDir: false},
&nameOnlyEntry{name: "real-dir", isDir: true},
&nameOnlyEntry{name: "a-dir", isDir: true},
}
SortEntries(entries, SortByName, func(e fs.DirEntry) bool {
if e.Type()&fs.ModeSymlink != 0 {
return true // simulated symlink-to-dir: group with dirs
}
return e.IsDir()
})

if got := entries[0].Name(); got != "a-dir" {
t.Errorf("first = %q, want dir", got)
}
if got := entries[1].Name(); got != "d-link" {
t.Errorf("second = %q, want symlink-to-dir grouped with dirs", got)
}
if got := entries[2].Name(); got != "real-dir" {
t.Errorf("third = %q, want dir", got)
}
for i, name := range []string{"a-dir", "d-link", "real-dir"} {
if entries[i].Name() != name {
t.Errorf("entries[%d] = %q, want %q", i, entries[i].Name(), name)
}
}
}
2 changes: 1 addition & 1 deletion internal/ui/panel/panel_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (m Model) renderRow(idx, width int, th theme.Theme) string {
info := m.infos[idx]

name := entry.Name()
isDir := entry.IsDir()
isDir := IsDirLike(&m, entry)
isCursor := idx == m.cursor && m.active
isSelected := m.selected[idx]

Expand Down
9 changes: 6 additions & 3 deletions internal/ui/panel/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ const (
)

// SortEntries sorts directory entries. Directories always come first.
func SortEntries(entries []fs.DirEntry, mode SortMode) {
// isDir classifies an entry as directory-like; callers should use it for both
// real directories and symlinks that resolve to directories so those sort into
// the same group.
func SortEntries(entries []fs.DirEntry, mode SortMode, isDir func(fs.DirEntry) bool) {
sort.SliceStable(entries, func(i, j int) bool {
a, b := entries[i], entries[j]

Expand All @@ -30,8 +33,8 @@ func SortEntries(entries []fs.DirEntry, mode SortMode) {
}

// Directories before files
aDir := a.IsDir()
bDir := b.IsDir()
aDir := isDir(a)
bDir := isDir(b)
if aDir != bDir {
return aDir
}
Expand Down
Loading