From 62621736b3e8d7fa151e4b62c7178beb13782d84 Mon Sep 17 00:00:00 2001 From: Ailac Date: Sat, 15 Oct 2022 14:48:05 +0200 Subject: [PATCH] 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 --- ui.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ui.go b/ui.go index 5faccc60..83c6dd19 100644 --- a/ui.go +++ b/ui.go @@ -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