diff --git a/eval.go b/eval.go index 789f41e..346e6a4 100644 --- a/eval.go +++ b/eval.go @@ -393,30 +393,30 @@ func update(app *app) { app.nav.search = string(app.ui.cmdAccLeft) + string(app.ui.cmdAccRight) dir := app.nav.currDir() + old := dir.ind dir.ind = app.nav.searchInd dir.pos = app.nav.searchPos - if err := app.nav.searchNext(); err != nil { + if _, err := app.nav.searchNext(); err != nil { app.ui.echoerrf("search: %s: %s", err, app.nav.search) - return + } else if old != dir.ind { + app.ui.loadFile(app.nav, true) + app.ui.loadFileInfo(app.nav) } - - app.ui.loadFile(app.nav, true) - app.ui.loadFileInfo(app.nav) case gOpts.incsearch && app.ui.cmdPrefix == "?": app.nav.search = string(app.ui.cmdAccLeft) + string(app.ui.cmdAccRight) dir := app.nav.currDir() + old := dir.ind dir.ind = app.nav.searchInd dir.pos = app.nav.searchPos - if err := app.nav.searchPrev(); err != nil { + if _, err := app.nav.searchPrev(); err != nil { app.ui.echoerrf("search: %s: %s", err, app.nav.search) - return + } else if old != dir.ind { + app.ui.loadFile(app.nav, true) + app.ui.loadFileInfo(app.nav) } - - app.ui.loadFile(app.nav, true) - app.ui.loadFileInfo(app.nav) } } @@ -455,9 +455,9 @@ func insert(app *app, arg string) { return } - if !app.nav.findNext() { + if moved, found := app.nav.findNext(); !found { app.ui.echoerrf("find: pattern not found: %s", app.nav.find) - } else { + } else if moved { app.ui.loadFile(app.nav, true) app.ui.loadFileInfo(app.nav) } @@ -484,9 +484,9 @@ func insert(app *app, arg string) { return } - if !app.nav.findPrev() { + if moved, found := app.nav.findPrev(); !found { app.ui.echoerrf("find-back: pattern not found: %s", app.nav.find) - } else { + } else if moved { app.ui.loadFile(app.nav, true) app.ui.loadFileInfo(app.nav) } @@ -854,6 +854,8 @@ func (e *callExpr) eval(app *app, args []string) { app.nav.findBack = true app.ui.loadFileInfo(app.nav) case "find-next": + dir := app.nav.currDir() + old := dir.ind for i := 0; i < e.count; i++ { if app.nav.findBack { app.nav.findPrev() @@ -861,9 +863,13 @@ func (e *callExpr) eval(app *app, args []string) { app.nav.findNext() } } - app.ui.loadFile(app.nav, true) - app.ui.loadFileInfo(app.nav) + if old != dir.ind { + app.ui.loadFile(app.nav, true) + app.ui.loadFileInfo(app.nav) + } case "find-prev": + dir := app.nav.currDir() + old := dir.ind for i := 0; i < e.count; i++ { if app.nav.findBack { app.nav.findNext() @@ -871,8 +877,10 @@ func (e *callExpr) eval(app *app, args []string) { app.nav.findPrev() } } - app.ui.loadFile(app.nav, true) - app.ui.loadFileInfo(app.nav) + if old != dir.ind { + app.ui.loadFile(app.nav, true) + app.ui.loadFileInfo(app.nav) + } case "search": app.ui.cmdPrefix = "/" dir := app.nav.currDir() @@ -890,35 +898,39 @@ func (e *callExpr) eval(app *app, args []string) { case "search-next": for i := 0; i < e.count; i++ { if app.nav.searchBack { - if err := app.nav.searchPrev(); err != nil { + if moved, err := app.nav.searchPrev(); err != nil { app.ui.echoerrf("search-back: %s: %s", err, app.nav.search) - return + } else if moved { + app.ui.loadFile(app.nav, true) + app.ui.loadFileInfo(app.nav) } } else { - if err := app.nav.searchNext(); err != nil { + if moved, err := app.nav.searchNext(); err != nil { app.ui.echoerrf("search: %s: %s", err, app.nav.search) - return + } else if moved { + app.ui.loadFile(app.nav, true) + app.ui.loadFileInfo(app.nav) } } } - app.ui.loadFile(app.nav, true) - app.ui.loadFileInfo(app.nav) case "search-prev": for i := 0; i < e.count; i++ { if app.nav.searchBack { - if err := app.nav.searchNext(); err != nil { + if moved, err := app.nav.searchNext(); err != nil { app.ui.echoerrf("search-back: %s: %s", err, app.nav.search) - return + } else if moved { + app.ui.loadFile(app.nav, true) + app.ui.loadFileInfo(app.nav) } } else { - if err := app.nav.searchPrev(); err != nil { + if moved, err := app.nav.searchPrev(); err != nil { app.ui.echoerrf("search: %s: %s", err, app.nav.search) - return + } else if moved { + app.ui.loadFile(app.nav, true) + app.ui.loadFileInfo(app.nav) } } } - app.ui.loadFile(app.nav, true) - app.ui.loadFileInfo(app.nav) case "mark-save": app.ui.cmdPrefix = "mark-save: " case "mark-load": @@ -1067,11 +1079,12 @@ func (e *callExpr) eval(app *app, args []string) { } if gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?") { dir := app.nav.currDir() - dir.ind = app.nav.searchInd dir.pos = app.nav.searchPos - - app.ui.loadFile(app.nav, true) - app.ui.loadFileInfo(app.nav) + if dir.ind != app.nav.searchInd { + dir.ind = app.nav.searchInd + app.ui.loadFile(app.nav, true) + app.ui.loadFileInfo(app.nav) + } } normal(app) case "cmd-complete": @@ -1235,32 +1248,34 @@ func (e *callExpr) eval(app *app, args []string) { app.cmdHistory = append(app.cmdHistory, cmdItem{"&", s}) app.runShell(s, nil, "&") case "/": + dir := app.nav.currDir() + old := dir.ind if gOpts.incsearch { - dir := app.nav.currDir() dir.ind = app.nav.searchInd dir.pos = app.nav.searchPos } log.Printf("search: %s", s) app.ui.cmdPrefix = "" app.nav.search = s - if err := app.nav.searchNext(); err != nil { + if _, err := app.nav.searchNext(); err != nil { app.ui.echoerrf("search: %s: %s", err, app.nav.search) - } else { + } else if old != dir.ind { app.ui.loadFile(app.nav, true) app.ui.loadFileInfo(app.nav) } case "?": + dir := app.nav.currDir() + old := dir.ind if gOpts.incsearch { - dir := app.nav.currDir() dir.ind = app.nav.searchInd dir.pos = app.nav.searchPos } log.Printf("search-back: %s", s) app.ui.cmdPrefix = "" app.nav.search = s - if err := app.nav.searchPrev(); err != nil { + if _, err := app.nav.searchPrev(); err != nil { app.ui.echoerrf("search-back: %s: %s", err, app.nav.search) - } else { + } else if old != dir.ind { app.ui.loadFile(app.nav, true) app.ui.loadFileInfo(app.nav) } diff --git a/nav.go b/nav.go index 9289fd2..3533cf2 100644 --- a/nav.go +++ b/nav.go @@ -1123,42 +1123,38 @@ func (nav *nav) findSingle() int { return count } -func (nav *nav) findNext() bool { +func (nav *nav) findNext() (bool, bool) { dir := nav.currDir() for i := dir.ind + 1; i < len(dir.files); i++ { if findMatch(dir.files[i].Name(), nav.find) { - nav.down(i - dir.ind) - return true + return nav.down(i - dir.ind), true } } if gOpts.wrapscan { for i := 0; i < dir.ind; i++ { if findMatch(dir.files[i].Name(), nav.find) { - nav.up(dir.ind - i) - return true + return nav.up(dir.ind - i), true } } } - return false + return false, false } -func (nav *nav) findPrev() bool { +func (nav *nav) findPrev() (bool, bool) { dir := nav.currDir() for i := dir.ind - 1; i >= 0; i-- { if findMatch(dir.files[i].Name(), nav.find) { - nav.up(dir.ind - i) - return true + return nav.up(dir.ind - i), true } } if gOpts.wrapscan { for i := len(dir.files) - 1; i > dir.ind; i-- { if findMatch(dir.files[i].Name(), nav.find) { - nav.down(i - dir.ind) - return true + return nav.down(i - dir.ind), true } } } - return false + return false, false } func searchMatch(name, pattern string) (matched bool, err error) { @@ -1182,58 +1178,46 @@ func searchMatch(name, pattern string) (matched bool, err error) { return strings.Contains(name, pattern), nil } -func (nav *nav) searchNext() error { +func (nav *nav) searchNext() (bool, error) { dir := nav.currDir() for i := dir.ind + 1; i < len(dir.files); i++ { - matched, err := searchMatch(dir.files[i].Name(), nav.search) - if err != nil { - return err - } - if matched { - nav.down(i - dir.ind) - return nil + if matched, err := searchMatch(dir.files[i].Name(), nav.search); err != nil { + return false, err + } else if matched { + return nav.down(i - dir.ind), nil } } if gOpts.wrapscan { for i := 0; i < dir.ind; i++ { - matched, err := searchMatch(dir.files[i].Name(), nav.search) - if err != nil { - return err - } - if matched { - nav.up(dir.ind - i) - return nil + if matched, err := searchMatch(dir.files[i].Name(), nav.search); err != nil { + return false, err + } else if matched { + return nav.up(dir.ind - i), nil } } } - return nil + return false, nil } -func (nav *nav) searchPrev() error { +func (nav *nav) searchPrev() (bool, error) { dir := nav.currDir() for i := dir.ind - 1; i >= 0; i-- { - matched, err := searchMatch(dir.files[i].Name(), nav.search) - if err != nil { - return err - } - if matched { - nav.up(dir.ind - i) - return nil + if matched, err := searchMatch(dir.files[i].Name(), nav.search); err != nil { + return false, err + } else if matched { + return nav.up(dir.ind - i), nil } } if gOpts.wrapscan { for i := len(dir.files) - 1; i > dir.ind; i-- { - matched, err := searchMatch(dir.files[i].Name(), nav.search) - if err != nil { - return err - } - if matched { - nav.down(i - dir.ind) - return nil + if matched, err := searchMatch(dir.files[i].Name(), nav.search); err != nil { + return false, err + } else if matched { + return nav.down(i - dir.ind), nil } } } - return nil + return false, nil } func (nav *nav) removeMark(mark string) error {