allow movement commands in cmap

Related #68
This commit is contained in:
Gokcehan 2019-05-14 20:21:24 +03:00
parent e815adc6a6
commit e69a229578

71
eval.go
View File

@ -370,6 +370,13 @@ func update(app *app) {
} }
} }
func normal(app *app) {
app.ui.menuBuf = nil
app.ui.cmdAccLeft = nil
app.ui.cmdAccRight = nil
app.ui.cmdPrefix = ""
}
func insert(app *app, arg string) { func insert(app *app, arg string) {
switch { switch {
case gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?"): case gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?"):
@ -403,10 +410,7 @@ func insert(app *app, arg string) {
} }
} }
app.ui.menuBuf = nil normal(app)
app.ui.cmdAccLeft = nil
app.ui.cmdAccRight = nil
app.ui.cmdPrefix = ""
case app.ui.cmdPrefix == "find-back: ": case app.ui.cmdPrefix == "find-back: ":
app.nav.find = string(app.ui.cmdAccLeft) + arg + string(app.ui.cmdAccRight) app.nav.find = string(app.ui.cmdAccLeft) + arg + string(app.ui.cmdAccRight)
@ -435,15 +439,9 @@ func insert(app *app, arg string) {
} }
} }
app.ui.menuBuf = nil normal(app)
app.ui.cmdAccLeft = nil
app.ui.cmdAccRight = nil
app.ui.cmdPrefix = ""
case app.ui.cmdPrefix == "delete?[y/N]: ": case app.ui.cmdPrefix == "delete?[y/N]: ":
app.ui.menuBuf = nil normal(app)
app.ui.cmdAccLeft = nil
app.ui.cmdAccRight = nil
app.ui.cmdPrefix = ""
if arg == "y" { if arg == "y" {
if err := app.nav.del(); err != nil { if err := app.nav.del(); err != nil {
@ -456,10 +454,7 @@ func insert(app *app, arg string) {
} }
} }
case app.ui.cmdPrefix == "mark-save: ": case app.ui.cmdPrefix == "mark-save: ":
app.ui.menuBuf = nil normal(app)
app.ui.cmdAccLeft = nil
app.ui.cmdAccRight = nil
app.ui.cmdPrefix = ""
wd, err := os.Getwd() wd, err := os.Getwd()
if err != nil { if err != nil {
@ -468,10 +463,7 @@ func insert(app *app, arg string) {
} }
app.nav.marks[arg] = wd app.nav.marks[arg] = wd
case app.ui.cmdPrefix == "mark-load: ": case app.ui.cmdPrefix == "mark-load: ":
app.ui.menuBuf = nil normal(app)
app.ui.cmdAccLeft = nil
app.ui.cmdAccRight = nil
app.ui.cmdPrefix = ""
wd, err := os.Getwd() wd, err := os.Getwd()
if err != nil { if err != nil {
@ -501,30 +493,51 @@ func insert(app *app, arg string) {
func (e *callExpr) eval(app *app, args []string) { func (e *callExpr) eval(app *app, args []string) {
switch e.name { switch e.name {
case "up": case "up":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
app.nav.up(e.count) app.nav.up(e.count)
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "half-up": case "half-up":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
app.nav.up(e.count * app.nav.height / 2) app.nav.up(e.count * app.nav.height / 2)
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "page-up": case "page-up":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
app.nav.up(e.count * app.nav.height) app.nav.up(e.count * app.nav.height)
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "down": case "down":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
app.nav.down(e.count) app.nav.down(e.count)
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "half-down": case "half-down":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
app.nav.down(e.count * app.nav.height / 2) app.nav.down(e.count * app.nav.height / 2)
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "page-down": case "page-down":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
app.nav.down(e.count * app.nav.height) app.nav.down(e.count * app.nav.height)
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "updir": case "updir":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
for i := 0; i < e.count; i++ { for i := 0; i < e.count; i++ {
if err := app.nav.updir(); err != nil { if err := app.nav.updir(); err != nil {
app.ui.echoerrf("%s", err) app.ui.echoerrf("%s", err)
@ -534,6 +547,9 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "open": case "open":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
curr, err := app.nav.currFile() curr, err := app.nav.currFile()
if err != nil { if err != nil {
app.ui.echoerrf("opening: %s", err) app.ui.echoerrf("opening: %s", err)
@ -841,10 +857,7 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
app.ui.menuBuf = nil normal(app)
app.ui.cmdAccLeft = nil
app.ui.cmdAccRight = nil
app.ui.cmdPrefix = ""
case "cmd-complete": case "cmd-complete":
var matches []string var matches []string
switch app.ui.cmdPrefix { switch app.ui.cmdPrefix {
@ -946,10 +959,7 @@ func (e *callExpr) eval(app *app, args []string) {
app.cmdHistoryInd-- app.cmdHistoryInd--
} }
if app.cmdHistoryInd == 0 { if app.cmdHistoryInd == 0 {
app.ui.menuBuf = nil normal(app)
app.ui.cmdAccLeft = nil
app.ui.cmdAccRight = nil
app.ui.cmdPrefix = ""
return return
} }
cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd] cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd]
@ -1035,10 +1045,7 @@ func (e *callExpr) eval(app *app, args []string) {
if app.cmd != nil { if app.cmd != nil {
app.cmd.Process.Kill() app.cmd.Process.Kill()
} }
app.ui.menuBuf = nil normal(app)
app.ui.cmdAccLeft = nil
app.ui.cmdAccRight = nil
app.ui.cmdPrefix = ""
case "cmd-word": case "cmd-word":
if len(app.ui.cmdAccRight) == 0 { if len(app.ui.cmdAccRight) == 0 {
return return