Cmap fixes (#691)

* fixed bug when switching commands

* filter and searches are now reset, whenever prompt is reset

* don't interrupt %-shell commands

* filter and search are now correctly started and stoped on cd

* movement commands now don't stop prompts

* forgot shell-pipe check in delete command
This commit is contained in:
SPFab 2021-08-29 17:28:29 +02:00 committed by GitHub
parent 5566f82596
commit 85aa3b9dc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 111 additions and 56 deletions

4
app.go
View File

@ -495,6 +495,9 @@ func (app *app) runShell(s string, args []string, prefix string) {
err = cmd.Run() err = cmd.Run()
case "%": case "%":
if app.ui.cmdPrefix == ">" {
return
}
stdin, err := cmd.StdinPipe() stdin, err := cmd.StdinPipe()
if err != nil { if err != nil {
log.Printf("writing stdin: %s", err) log.Printf("writing stdin: %s", err)
@ -524,6 +527,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
switch prefix { switch prefix {
case "%": case "%":
normal(app)
app.cmd = cmd app.cmd = cmd
app.cmdOutBuf = nil app.cmdOutBuf = nil
app.ui.msg = "" app.ui.msg = ""

163
eval.go
View File

@ -532,7 +532,42 @@ func update(app *app) {
} }
} }
func restartIncCmd(app *app) {
if gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?") {
dir := app.nav.currDir()
app.nav.searchInd = dir.ind
app.nav.searchPos = dir.pos
update(app)
} else if gOpts.incfilter && app.ui.cmdPrefix == "filter: " {
dir := app.nav.currDir()
app.nav.prevFilter = dir.filter
update(app)
}
}
func resetIncCmd(app *app) {
if gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?") {
dir := app.nav.currDir()
dir.pos = app.nav.searchPos
if dir.ind != app.nav.searchInd {
dir.ind = app.nav.searchInd
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
} else if gOpts.incfilter && app.ui.cmdPrefix == "filter: " {
dir := app.nav.currDir()
old := dir.ind
app.nav.setFilter(app.nav.prevFilter)
if old != dir.ind {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
}
}
func normal(app *app) { func normal(app *app) {
resetIncCmd(app)
app.ui.menuBuf = nil app.ui.menuBuf = nil
app.ui.menuSelected = -2 app.ui.menuSelected = -2
@ -704,6 +739,7 @@ func insert(app *app, arg string) {
} }
if wd != path { if wd != path {
resetIncCmd(app)
preChdir(app) preChdir(app)
} }
@ -716,6 +752,7 @@ func insert(app *app, arg string) {
if wd != path { if wd != path {
app.nav.marks["'"] = wd app.nav.marks["'"] = wd
restartIncCmd(app)
onChdir(app) onChdir(app)
} }
case app.ui.cmdPrefix == "mark-remove: ": case app.ui.cmdPrefix == "mark-remove: ":
@ -745,57 +782,37 @@ 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)
}
if app.nav.up(e.count) { if app.nav.up(e.count) {
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
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)
}
if app.nav.up(e.count * app.nav.height / 2) { if app.nav.up(e.count * app.nav.height / 2) {
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
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)
}
if app.nav.up(e.count * app.nav.height) { if app.nav.up(e.count * app.nav.height) {
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case "down": case "down":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
if app.nav.down(e.count) { if app.nav.down(e.count) {
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
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)
}
if app.nav.down(e.count * app.nav.height / 2) { if app.nav.down(e.count * app.nav.height / 2) {
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
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)
}
if app.nav.down(e.count * app.nav.height) { if app.nav.down(e.count * app.nav.height) {
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case "updir": case "updir":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" { resetIncCmd(app)
normal(app)
}
preChdir(app) preChdir(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 {
@ -805,11 +822,9 @@ func (e *callExpr) eval(app *app, args []string) {
} }
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
restartIncCmd(app)
onChdir(app) onChdir(app)
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)
@ -817,6 +832,7 @@ func (e *callExpr) eval(app *app, args []string) {
} }
if curr.IsDir() { if curr.IsDir() {
resetIncCmd(app)
preChdir(app) preChdir(app)
err := app.nav.open() err := app.nav.open()
if err != nil { if err != nil {
@ -825,6 +841,7 @@ func (e *callExpr) eval(app *app, args []string) {
} }
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
restartIncCmd(app)
onChdir(app) onChdir(app)
return return
} }
@ -860,17 +877,11 @@ func (e *callExpr) eval(app *app, args []string) {
case "quit": case "quit":
app.quitChan <- struct{}{} app.quitChan <- struct{}{}
case "top": case "top":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
if app.nav.top() { if app.nav.top() {
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case "bottom": case "bottom":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
if app.nav.bottom() { if app.nav.bottom() {
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
@ -961,6 +972,10 @@ func (e *callExpr) eval(app *app, args []string) {
return return
} }
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
if len(list) == 1 { if len(list) == 1 {
app.ui.cmdPrefix = "delete '" + list[0] + "' ? [y/N] " app.ui.cmdPrefix = "delete '" + list[0] + "' ? [y/N] "
} else { } else {
@ -1005,25 +1020,53 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "read": case "read":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = ":" app.ui.cmdPrefix = ":"
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "shell": case "shell":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "$" app.ui.cmdPrefix = "$"
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "shell-pipe": case "shell-pipe":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "%" app.ui.cmdPrefix = "%"
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "shell-wait": case "shell-wait":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "!" app.ui.cmdPrefix = "!"
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "shell-async": case "shell-async":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "&" app.ui.cmdPrefix = "&"
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "find": case "find":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "find: " app.ui.cmdPrefix = "find: "
app.nav.findBack = false app.nav.findBack = false
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "find-back": case "find-back":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "find-back: " app.ui.cmdPrefix = "find-back: "
app.nav.findBack = true app.nav.findBack = true
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
@ -1056,6 +1099,10 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case "search": case "search":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "/" app.ui.cmdPrefix = "/"
dir := app.nav.currDir() dir := app.nav.currDir()
app.nav.searchInd = dir.ind app.nav.searchInd = dir.ind
@ -1063,6 +1110,10 @@ func (e *callExpr) eval(app *app, args []string) {
app.nav.searchBack = false app.nav.searchBack = false
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "search-back": case "search-back":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "?" app.ui.cmdPrefix = "?"
dir := app.nav.currDir() dir := app.nav.currDir()
app.nav.searchInd = dir.ind app.nav.searchInd = dir.ind
@ -1106,6 +1157,10 @@ func (e *callExpr) eval(app *app, args []string) {
} }
} }
case "filter": case "filter":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "filter: " app.ui.cmdPrefix = "filter: "
dir := app.nav.currDir() dir := app.nav.currDir()
app.nav.prevFilter = dir.filter app.nav.prevFilter = dir.filter
@ -1123,11 +1178,23 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "mark-save": case "mark-save":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "mark-save: " app.ui.cmdPrefix = "mark-save: "
case "mark-load": case "mark-load":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.menuBuf = listMarks(app.nav.marks) app.ui.menuBuf = listMarks(app.nav.marks)
app.ui.cmdPrefix = "mark-load: " app.ui.cmdPrefix = "mark-load: "
case "mark-remove": case "mark-remove":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.menuBuf = listMarks(app.nav.marks) app.ui.menuBuf = listMarks(app.nav.marks)
app.ui.cmdPrefix = "mark-remove: " app.ui.cmdPrefix = "mark-remove: "
case "rename": case "rename":
@ -1148,6 +1215,10 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.echoerrf("rename: %s:", err) app.ui.echoerrf("rename: %s:", err)
return return
} }
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "rename: " app.ui.cmdPrefix = "rename: "
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name())...) app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name())...)
} }
@ -1182,6 +1253,7 @@ func (e *callExpr) eval(app *app, args []string) {
} }
if wd != path { if wd != path {
resetIncCmd(app)
preChdir(app) preChdir(app)
} }
@ -1195,6 +1267,7 @@ func (e *callExpr) eval(app *app, args []string) {
if wd != path { if wd != path {
app.nav.marks["'"] = wd app.nav.marks["'"] = wd
restartIncCmd(app)
onChdir(app) onChdir(app)
} }
case "select": case "select":
@ -1216,6 +1289,7 @@ func (e *callExpr) eval(app *app, args []string) {
} }
if wd != path { if wd != path {
resetIncCmd(app)
preChdir(app) preChdir(app)
} }
@ -1229,6 +1303,7 @@ func (e *callExpr) eval(app *app, args []string) {
if wd != path { if wd != path {
app.nav.marks["'"] = wd app.nav.marks["'"] = wd
restartIncCmd(app)
onChdir(app) onChdir(app)
} }
case "glob-select": case "glob-select":
@ -1282,24 +1357,6 @@ func (e *callExpr) eval(app *app, args []string) {
if app.ui.cmdPrefix == ">" { if app.ui.cmdPrefix == ">" {
return return
} }
if gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?") {
dir := app.nav.currDir()
dir.pos = app.nav.searchPos
if dir.ind != app.nav.searchInd {
dir.ind = app.nav.searchInd
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
}
if gOpts.incfilter && app.ui.cmdPrefix == "filter: " {
dir := app.nav.currDir()
old := dir.ind
app.nav.setFilter(app.nav.prevFilter)
if old != dir.ind {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
}
normal(app) normal(app)
case "cmd-complete": case "cmd-complete":
var matches []string var matches []string
@ -1597,12 +1654,9 @@ func (e *callExpr) eval(app *app, args []string) {
return return
} }
cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd] cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd]
normal(app)
app.ui.cmdPrefix = cmd.prefix app.ui.cmdPrefix = cmd.prefix
app.ui.cmdAccLeft = []rune(cmd.value) app.ui.cmdAccLeft = []rune(cmd.value)
app.ui.cmdAccRight = nil
app.ui.cmdTmp = nil
app.ui.menuBuf = nil
app.ui.menuSelected = -2
case "cmd-history-prev": case "cmd-history-prev":
if app.ui.cmdPrefix == ">" { if app.ui.cmdPrefix == ">" {
return return
@ -1615,12 +1669,9 @@ func (e *callExpr) eval(app *app, args []string) {
} }
app.cmdHistoryInd++ app.cmdHistoryInd++
cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd] cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd]
normal(app)
app.ui.cmdPrefix = cmd.prefix app.ui.cmdPrefix = cmd.prefix
app.ui.cmdAccLeft = []rune(cmd.value) app.ui.cmdAccLeft = []rune(cmd.value)
app.ui.cmdAccRight = nil
app.ui.cmdTmp = nil
app.ui.menuBuf = nil
app.ui.menuSelected = -2
case "cmd-delete": case "cmd-delete":
if len(app.ui.cmdAccRight) == 0 { if len(app.ui.cmdAccRight) == 0 {
return return