select new file after rename

Related #197
This commit is contained in:
Gokcehan 2020-07-17 00:28:32 +03:00
parent e7fb56391f
commit 2f056ad359
2 changed files with 32 additions and 12 deletions

31
eval.go
View File

@ -492,8 +492,7 @@ func insert(app *app, arg string) {
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case strings.HasPrefix(app.ui.cmdPrefix, "replace") || case strings.HasPrefix(app.ui.cmdPrefix, "replace"):
strings.HasPrefix(app.ui.cmdPrefix, "create path"):
normal(app) normal(app)
if arg == "y" { if arg == "y" {
@ -508,6 +507,25 @@ func insert(app *app, arg string) {
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(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: ": case app.ui.cmdPrefix == "mark-save: ":
normal(app) normal(app)
@ -1117,11 +1135,10 @@ func (e *callExpr) eval(app *app, args []string) {
app.nav.renameOldPath = oldPath app.nav.renameOldPath = oldPath
app.nav.renameNewPath = newPath app.nav.renameNewPath = newPath
if dir, _ := filepath.Split(s); dir != "" { newDir := filepath.Dir(newPath)
if _, err := os.Stat(filepath.Join(wd, dir)); err != nil { if _, err := os.Stat(newDir); os.IsNotExist(err) {
app.ui.cmdPrefix = "create path " + dir + "?[y/N]" app.ui.cmdPrefix = "create path " + newDir + "?[y/N]"
return return
}
} }
oldStat, err := os.Stat(oldPath) oldStat, err := os.Stat(oldPath)

13
nav.go
View File

@ -854,18 +854,21 @@ func (nav *nav) rename() error {
oldPath := nav.renameOldPath oldPath := nav.renameOldPath
newPath := nav.renameNewPath newPath := nav.renameNewPath
dir, _ := filepath.Split(newPath)
os.MkdirAll(dir, os.ModePerm)
if err := os.Rename(oldPath, newPath); err != nil { if err := os.Rename(oldPath, newPath); err != nil {
return err return err
} }
// TODO: change selection lstat, err := os.Lstat(newPath)
if err := nav.sel(newPath); err != nil { if err != nil {
return err 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 return nil
} }