diff --git a/eval.go b/eval.go index b4bda50..5ffa4cc 100644 --- a/eval.go +++ b/eval.go @@ -492,8 +492,7 @@ func insert(app *app, arg string) { app.ui.loadFile(app.nav) app.ui.loadFileInfo(app.nav) } - case strings.HasPrefix(app.ui.cmdPrefix, "replace") || - strings.HasPrefix(app.ui.cmdPrefix, "create path"): + case strings.HasPrefix(app.ui.cmdPrefix, "replace"): normal(app) if arg == "y" { @@ -508,6 +507,25 @@ func insert(app *app, arg string) { app.ui.loadFile(app.nav) app.ui.loadFileInfo(app.nav) } + case strings.HasPrefix(app.ui.cmdPrefix, "create path"): + normal(app) + + if arg == "y" { + if err := os.MkdirAll(filepath.Dir(app.nav.renameNewPath), os.ModePerm); err != nil { + app.ui.echoerrf("rename: %s", err) + return + } + if err := app.nav.rename(); err != nil { + app.ui.echoerrf("rename: %s", err) + return + } + if err := remote("send load"); err != nil { + app.ui.echoerrf("rename: %s", err) + return + } + app.ui.loadFile(app.nav) + app.ui.loadFileInfo(app.nav) + } case app.ui.cmdPrefix == "mark-save: ": normal(app) @@ -1117,11 +1135,10 @@ func (e *callExpr) eval(app *app, args []string) { app.nav.renameOldPath = oldPath app.nav.renameNewPath = newPath - if dir, _ := filepath.Split(s); dir != "" { - if _, err := os.Stat(filepath.Join(wd, dir)); err != nil { - app.ui.cmdPrefix = "create path " + dir + "?[y/N]" - return - } + newDir := filepath.Dir(newPath) + if _, err := os.Stat(newDir); os.IsNotExist(err) { + app.ui.cmdPrefix = "create path " + newDir + "?[y/N]" + return } oldStat, err := os.Stat(oldPath) diff --git a/nav.go b/nav.go index 8d9f91c..ca00f84 100644 --- a/nav.go +++ b/nav.go @@ -854,18 +854,21 @@ func (nav *nav) rename() error { oldPath := nav.renameOldPath newPath := nav.renameNewPath - dir, _ := filepath.Split(newPath) - os.MkdirAll(dir, os.ModePerm) - if err := os.Rename(oldPath, newPath); err != nil { return err } - // TODO: change selection - if err := nav.sel(newPath); err != nil { + lstat, err := os.Lstat(newPath) + if err != nil { return err } + dir := nav.loadDir(filepath.Dir(newPath)) + dir.files = append(dir.files, &file{FileInfo: lstat}) + dir.sel(lstat.Name(), nav.height) + + nav.checkDir(dir) + return nil }