summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2015-07-16 19:18:23 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2015-07-16 21:14:08 +0900
commita0e6147bb57f5a4ba4b9c78a4e2d14989376c1fe (patch)
treee60db7b76a51593f1ed26871366843464dd0afcc /src
parentb0f491d3c3a3463b88b95c98f2a08abfdcccb087 (diff)
downloadfzf-a0e6147bb57f5a4ba4b9c78a4e2d14989376c1fe.tar.gz
Fix #292 - Allow binding of colon and comma
Diffstat (limited to 'src')
-rw-r--r--src/options.go38
-rw-r--r--src/options_test.go4
2 files changed, 30 insertions, 12 deletions
diff --git a/src/options.go b/src/options.go
index 4f79d33a..1f535494 100644
--- a/src/options.go
+++ b/src/options.go
@@ -430,6 +430,11 @@ func firstKey(keymap map[int]string) int {
return 0
}
+const (
+ escapedColon = 0
+ escapedComma = 1
+)
+
func parseKeymap(keymap map[int]actionType, execmap map[int]string, toggleSort bool, str string) (map[int]actionType, map[int]string, bool) {
if executeRegexp == nil {
// Backreferences are not supported.
@@ -440,10 +445,12 @@ func parseKeymap(keymap map[int]actionType, execmap map[int]string, toggleSort b
masked := executeRegexp.ReplaceAllStringFunc(str, func(src string) string {
return ":execute(" + strings.Repeat(" ", len(src)-10) + ")"
})
+ masked = strings.Replace(masked, "::", string([]rune{escapedColon, ':'}), -1)
+ masked = strings.Replace(masked, ",:", string([]rune{escapedComma, ':'}), -1)
idx := 0
for _, pairStr := range strings.Split(masked, ",") {
- pairStr = str[idx : idx+len(pairStr)]
+ origPairStr := str[idx : idx+len(pairStr)]
idx += len(pairStr) + 1
fail := func() {
@@ -453,13 +460,22 @@ func parseKeymap(keymap map[int]actionType, execmap map[int]string, toggleSort b
if len(pair) != 2 {
fail()
}
- keys := parseKeyChords(pair[0], "key name required")
- if len(keys) != 1 {
- fail()
+ var key int
+ if len(pair[0]) == 1 && pair[0][0] == escapedColon {
+ key = ':' + curses.AltZ
+ } else if len(pair[0]) == 1 && pair[0][0] == escapedComma {
+ key = ',' + curses.AltZ
+ } else {
+ keys := parseKeyChords(pair[0], "key name required")
+ if len(keys) != 1 {
+ fail()
+ }
+ key = firstKey(keys)
}
- key := firstKey(keys)
- act := strings.ToLower(pair[1])
- switch act {
+
+ act := origPairStr[len(pair[0])+1 : len(origPairStr)]
+ actLower := strings.ToLower(act)
+ switch actLower {
case "ignore":
keymap[key] = actIgnore
case "beginning-of-line":
@@ -524,12 +540,12 @@ func parseKeymap(keymap map[int]actionType, execmap map[int]string, toggleSort b
keymap[key] = actToggleSort
toggleSort = true
default:
- if isExecuteAction(act) {
+ if isExecuteAction(actLower) {
keymap[key] = actExecute
- if pair[1][7] == ':' {
- execmap[key] = pair[1][8:]
+ if act[7] == ':' {
+ execmap[key] = act[8:]
} else {
- execmap[key] = pair[1][8 : len(act)-1]
+ execmap[key] = act[8 : len(act)-1]
}
} else {
errorExit("unknown action: " + act)
diff --git a/src/options_test.go b/src/options_test.go
index 8e44585d..28a8d9db 100644
--- a/src/options_test.go
+++ b/src/options_test.go
@@ -188,13 +188,15 @@ func TestBind(t *testing.T) {
"ctrl-a:kill-line,ctrl-b:toggle-sort,c:page-up,alt-z:page-down,"+
"f1:execute(ls {}),f2:execute/echo {}, {}, {}/,f3:execute[echo '({})'],f4:execute;less {};,"+
"alt-a:execute@echo (,),[,],/,:,;,%,{}@,alt-b:execute;echo (,),[,],/,:,@,%,{};"+
- ",X:execute:\nfoobar,Y:execute(baz)")
+ ",,:abort,::accept,X:execute:\nfoobar,Y:execute(baz)")
if !toggleSort {
t.Errorf("toggleSort not set")
}
check(actKillLine, keymap[curses.CtrlA])
check(actToggleSort, keymap[curses.CtrlB])
check(actPageUp, keymap[curses.AltZ+'c'])
+ check(actAbort, keymap[curses.AltZ+','])
+ check(actAccept, keymap[curses.AltZ+':'])
check(actPageDown, keymap[curses.AltZ])
check(actExecute, keymap[curses.F1])
check(actExecute, keymap[curses.F2])