Fix #292 - Allow binding of colon and comma
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Junegunn Choi · committed by Junegunn Choi · parent b0f491d · Browse files · 2 files·+30 added−12 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+30 added−12 removed
- other:+30 added−12 removed
Provenance
- Commit
a0e6147- Tree
e60db7b- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
b0f491d
2 files changed+30 added−12 removed
modified:src/options_test.go+3 added-1 removed
186 unmodified lines187 parseKeymap(keymap, execmap, false,188 "ctrl-a:kill-line,ctrl-b:toggle-sort,c:page-up,alt-z:page-down,"+189 "f1:execute(ls {}),f2:execute/echo {}, {}, {}/,f3:execute[echo '({})'],f4:execute;less {};,"+190 "alt-a:execute@echo (,),[,],/,:,;,%,{}@,alt-b:execute;echo (,),[,],/,:,@,%,{};"+191- ",X:execute:\nfoobar,Y:execute(baz)")191+ ",,:abort,::accept,X:execute:\nfoobar,Y:execute(baz)")192 if !toggleSort {193 t.Errorf("toggleSort not set")194 }195 check(actKillLine, keymap[curses.CtrlA])196 check(actToggleSort, keymap[curses.CtrlB])197 check(actPageUp, keymap[curses.AltZ+'c'])198+ check(actAbort, keymap[curses.AltZ+','])199+ check(actAccept, keymap[curses.AltZ+':'])200 check(actPageDown, keymap[curses.AltZ])201 check(actExecute, keymap[curses.F1])202 check(actExecute, keymap[curses.F2])203 check(actExecute, keymap[curses.F3])67 unmodified linesmodified:src/options.go+27 added-11 removed
428 unmodified lines429 }430 return 0431 }432 433+const (434+ escapedColon = 0435+ escapedComma = 1436+)437+438 func parseKeymap(keymap map[int]actionType, execmap map[int]string, toggleSort bool, str string) (map[int]actionType, map[int]string, bool) {439 if executeRegexp == nil {440 // Backreferences are not supported.441 // "~!@#$%^&*;/|".each_char.map { |c| Regexp.escape(c) }.map { |c| "#{c}[^#{c}]*#{c}" }.join('|')2 unmodified lines444 }445 masked := executeRegexp.ReplaceAllStringFunc(str, func(src string) string {446 return ":execute(" + strings.Repeat(" ", len(src)-10) + ")"447 })448+ masked = strings.Replace(masked, "::", string([]rune{escapedColon, ':'}), -1)449+ masked = strings.Replace(masked, ",:", string([]rune{escapedComma, ':'}), -1)450 451 idx := 0452 for _, pairStr := range strings.Split(masked, ",") {446- pairStr = str[idx : idx+len(pairStr)]453+ origPairStr := str[idx : idx+len(pairStr)]454 idx += len(pairStr) + 1455 456 fail := func() {457 errorExit("invalid key binding: " + pairStr)1 unmodified line459 pair := strings.SplitN(pairStr, ":", 2)460 if len(pair) != 2 {461 fail()462 }463+ var key int464+ if len(pair[0]) == 1 && pair[0][0] == escapedColon {465+ key = ':' + curses.AltZ466+ } else if len(pair[0]) == 1 && pair[0][0] == escapedComma {467+ key = ',' + curses.AltZ468+ } else {456- keys := parseKeyChords(pair[0], "key name required")457- if len(keys) != 1 {458- fail()469+ keys := parseKeyChords(pair[0], "key name required")470+ if len(keys) != 1 {471+ fail()472+ }473+ key = firstKey(keys)474 }460- key := firstKey(keys)461- act := strings.ToLower(pair[1])462- switch act {475+476+ act := origPairStr[len(pair[0])+1 : len(origPairStr)]477+ actLower := strings.ToLower(act)478+ switch actLower {479 case "ignore":480 keymap[key] = actIgnore481 case "beginning-of-line":482 keymap[key] = actBeginningOfLine56 unmodified lines539 case "toggle-sort":540 keymap[key] = actToggleSort541 toggleSort = true542 default:527- if isExecuteAction(act) {543+ if isExecuteAction(actLower) {544 keymap[key] = actExecute529- if pair[1][7] == ':' {530- execmap[key] = pair[1][8:]545+ if act[7] == ':' {546+ execmap[key] = act[8:]547 } else {532- execmap[key] = pair[1][8 : len(act)-1]548+ execmap[key] = act[8 : len(act)-1]549 }550 } else {551 errorExit("unknown action: " + act)552 }244 unmodified lines