From 1683cdfd47bcdac5ebfda2bcf7cf1c977603e6dc Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Wed, 5 Oct 2016 18:26:55 +0300 Subject: [PATCH] check if the directory is empty before nav operations Mentioned in #23. --- nav.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/nav.go b/nav.go index be944fd..48310d1 100644 --- a/nav.go +++ b/nav.go @@ -344,6 +344,10 @@ func (nav *Nav) cd(wd string) error { } func (nav *Nav) toggle() { + if nav.currEmpty() { + return + } + path := nav.currPath() if nav.marks[path] { @@ -357,6 +361,10 @@ func (nav *Nav) toggle() { func (nav *Nav) save(keep bool) error { if len(nav.marks) == 0 { + if nav.currEmpty() { + return errors.New("no file selected") + } + path := nav.currPath() if err := saveFiles([]string{path}, keep); err != nil { @@ -413,6 +421,10 @@ func (nav *Nav) paste() error { return nil } +func (nav *Nav) currEmpty() bool { + return len(nav.dirs[len(nav.dirs)-1].fi) == 0 +} + func (nav *Nav) currDir() *Dir { return nav.dirs[len(nav.dirs)-1] }