More alternative notations for execute action
execute(...) execute[...] execute~...~ execute!...! execute@...@ execute#...# execute$...$ execute%...% execute^...^ execute&...& execute*...* execute:...: execute;...; execute/.../ execute|...|
This commit is contained in:
parent
6c99cc1700
commit
022435a90a
@ -377,10 +377,16 @@ func parseTheme(defaultTheme *curses.ColorTheme, str string) *curses.ColorTheme
|
|||||||
return theme
|
return theme
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var executeRegexp *regexp.Regexp
|
||||||
|
|
||||||
func parseKeymap(keymap map[int]actionType, execmap map[int]string, toggleSort bool, str string) (map[int]actionType, map[int]string, bool) {
|
func parseKeymap(keymap map[int]actionType, execmap map[int]string, toggleSort bool, str string) (map[int]actionType, map[int]string, bool) {
|
||||||
rx := regexp.MustCompile(
|
if executeRegexp == nil {
|
||||||
":execute(\\([^)]*\\)|\\[[^\\]]*\\]|/[^/]*/|:[^:]*:|;[^;]*;|@[^@]*@|~[^~]*~|%[^%]*%|\\?[^?]*\\?)")
|
// Backreferences are not supported.
|
||||||
masked := rx.ReplaceAllStringFunc(str, func(src string) string {
|
// "~!@#$%^&*:;/|".each_char.map { |c| Regexp.escape(c) }.map { |c| "#{c}[^#{c}]*#{c}" }.join('|')
|
||||||
|
executeRegexp = regexp.MustCompile(
|
||||||
|
":execute(\\([^)]*\\)|\\[[^\\]]*\\]|~[^~]*~|![^!]*!|@[^@]*@|\\#[^\\#]*\\#|\\$[^\\$]*\\$|%[^%]*%|\\^[^\\^]*\\^|&[^&]*&|\\*[^\\*]*\\*|:[^:]*:|;[^;]*;|/[^/]*/|\\|[^\\|]*\\|)")
|
||||||
|
}
|
||||||
|
masked := executeRegexp.ReplaceAllStringFunc(str, func(src string) string {
|
||||||
return ":execute(" + strings.Repeat(" ", len(src)-10) + ")"
|
return ":execute(" + strings.Repeat(" ", len(src)-10) + ")"
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -484,7 +490,7 @@ func isExecuteAction(str string) bool {
|
|||||||
}
|
}
|
||||||
b := str[7]
|
b := str[7]
|
||||||
e := str[len(str)-1]
|
e := str[len(str)-1]
|
||||||
if b == e && strings.ContainsAny(string(b), "/:;@~%?") ||
|
if b == e && strings.ContainsAny(string(b), "~!@#$%^&*:;/|") ||
|
||||||
b == '(' && e == ')' || b == '[' && e == ']' {
|
b == '(' && e == ')' || b == '[' && e == ']' {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package fzf
|
package fzf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/junegunn/fzf/src/curses"
|
"github.com/junegunn/fzf/src/curses"
|
||||||
@ -167,6 +168,12 @@ func TestBind(t *testing.T) {
|
|||||||
checkString("echo (,),[,],/,:,;,%,{}", execmap[curses.AltA])
|
checkString("echo (,),[,],/,:,;,%,{}", execmap[curses.AltA])
|
||||||
checkString("echo (,),[,],/,:,@,%,{}", execmap[curses.AltB])
|
checkString("echo (,),[,],/,:,@,%,{}", execmap[curses.AltB])
|
||||||
|
|
||||||
|
for idx, char := range []rune{'~', '!', '@', '#', '$', '%', '^', '&', '*', '|', ':', ';', '/'} {
|
||||||
|
keymap, execmap, toggleSort =
|
||||||
|
parseKeymap(keymap, execmap, false, fmt.Sprintf("%d:execute%cfoobar%c", idx%10, char, char))
|
||||||
|
checkString("foobar", execmap[curses.AltZ+int([]rune(fmt.Sprintf("%d", idx%10))[0])])
|
||||||
|
}
|
||||||
|
|
||||||
keymap, execmap, toggleSort = parseKeymap(keymap, execmap, false, "f1:abort")
|
keymap, execmap, toggleSort = parseKeymap(keymap, execmap, false, "f1:abort")
|
||||||
if toggleSort {
|
if toggleSort {
|
||||||
t.Errorf("toggleSort set")
|
t.Errorf("toggleSort set")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user