Getting command count from definition (#863)

* Get command default count from definition

The command count defined in opts.go will be respected. In order to do that a copy of the callExpr or listExpr command is created so that the defined count is not overridden.

* Copy the command only if we need to overwrite the count
This commit is contained in:
Ailac authored and GitHub committed 2022-10-15 15:48:05 +03:00
1 parent 21a32a7603
commit 62621736b3
1 file changed
+9 -5
+9 -5
View File
@@ -1036,7 +1036,7 @@ func (ui *ui) pollEvent() tcell.Event {
// preceding any non-digit characters (e.g. "42y2k" as 42 times "y2k").
func (ui *ui) readNormalEvent(ev tcell.Event) expr {
draw := &callExpr{"draw", nil, 1}
count := 1
count := 0
switch tev := ev.(type) {
case *tcell.EventKey:
@@ -1090,11 +1090,15 @@ func (ui *ui) readNormalEvent(ev tcell.Event) expr {
count = c
}
expr := gOpts.keys[string(ui.keyAcc)]
if e, ok := expr.(*callExpr); ok {
e.count = count
} else if e, ok := expr.(*listExpr); ok {
e.count = count
if e, ok := expr.(*callExpr); ok && count != 0 {
expr = &callExpr{e.name, e.args, e.count}
expr.(*callExpr).count = count
} else if e, ok := expr.(*listExpr); ok && count != 0 {
expr = &listExpr{e.exprs, e.count}
expr.(*listExpr).count = count
}
ui.keyAcc = nil
ui.keyCount = nil
ui.menuBuf = nil