Add support for ctrl-alt-[a-z] key chords

Close #906
pull/909/head
Junegunn Choi 7 years ago
parent d5e72bf55d
commit 6b592137b9
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

@ -21,7 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
..
.TH fzf 1 "Mar 2017" "fzf 0.16.6" "fzf - a command-line fuzzy finder"
.TH fzf 1 "Apr 2017" "fzf 0.16.7" "fzf - a command-line fuzzy finder"
.SH NAME
fzf - a command-line fuzzy finder
@ -439,6 +439,7 @@ e.g. \fBfzf --bind=ctrl-j:accept,ctrl-k:kill-line\fR
.B AVAILABLE KEYS: (SYNONYMS)
\fIctrl-[a-z]\fR
\fIctrl-space\fR
\fIctrl-alt-[a-z]\fR
\fIalt-[a-z]\fR
\fIalt-[0-9]\fR
\fIf[1-12]\fR

@ -401,7 +401,7 @@ func parseKeyChords(str string, message string) map[int]string {
case "ctrl-space":
chord = tui.CtrlSpace
case "alt-enter", "alt-return":
chord = tui.AltEnter
chord = tui.CtrlAltM
case "alt-space":
chord = tui.AltSpace
case "alt-/":
@ -437,7 +437,9 @@ func parseKeyChords(str string, message string) map[int]string {
case "f12":
chord = tui.F12
default:
if len(key) == 6 && strings.HasPrefix(lkey, "ctrl-") && isAlphabet(lkey[5]) {
if len(key) == 10 && strings.HasPrefix(lkey, "ctrl-alt-") && isAlphabet(lkey[9]) {
chord = tui.CtrlAltA + int(lkey[9]) - 'a'
} else if len(key) == 6 && strings.HasPrefix(lkey, "ctrl-") && isAlphabet(lkey[5]) {
chord = tui.CtrlA + int(lkey[5]) - 'a'
} else if len(key) == 5 && strings.HasPrefix(lkey, "alt-") && isAlphabet(lkey[4]) {
chord = tui.AltA + int(lkey[4]) - 'a'

@ -125,14 +125,14 @@ func TestIrrelevantNth(t *testing.T) {
}
func TestParseKeys(t *testing.T) {
pairs := parseKeyChords("ctrl-z,alt-z,f2,@,Alt-a,!,ctrl-G,J,g,ALT-enter,alt-SPACE", "")
pairs := parseKeyChords("ctrl-z,alt-z,f2,@,Alt-a,!,ctrl-G,J,g,ctrl-alt-a,ALT-enter,alt-SPACE", "")
check := func(i int, s string) {
if pairs[i] != s {
t.Errorf("%s != %s", pairs[i], s)
}
}
if len(pairs) != 11 {
t.Error(11)
if len(pairs) != 12 {
t.Error(12)
}
check(tui.CtrlZ, "ctrl-z")
check(tui.AltZ, "alt-z")
@ -143,7 +143,8 @@ func TestParseKeys(t *testing.T) {
check(tui.CtrlA+'g'-'a', "ctrl-G")
check(tui.AltZ+'J', "J")
check(tui.AltZ+'g', "g")
check(tui.AltEnter, "ALT-enter")
check(tui.CtrlAltA, "ctrl-alt-a")
check(tui.CtrlAltM, "ALT-enter")
check(tui.AltSpace, "alt-SPACE")
// Synonyms

@ -344,9 +344,10 @@ func (r *LightRenderer) escSequence(sz *int) Event {
return Event{ESC, 0, nil}
}
*sz = 2
if r.buffer[1] >= 1 && r.buffer[1] <= 'z'-'a'+1 {
return Event{int(CtrlAltA + r.buffer[1] - 1), 0, nil}
}
switch r.buffer[1] {
case 13:
return Event{AltEnter, 0, nil}
case 32:
return Event{AltSpace, 0, nil}
case 47:

@ -353,7 +353,7 @@ func escSequence() Event {
case C.ERR:
return Event{ESC, 0, nil}
case CtrlM:
return Event{AltEnter, 0, nil}
return Event{CtrlAltM, 0, nil}
case '/':
return Event{AltSlash, 0, nil}
case ' ':

@ -221,58 +221,65 @@ func (r *FullscreenRenderer) GetChar() Event {
// process keyboard:
case *tcell.EventKey:
alt := (ev.Modifiers() & tcell.ModAlt) > 0
keyfn := func(r rune) int {
if alt {
return CtrlAltA - 'a' + int(r)
}
return CtrlA - 'a' + int(r)
}
switch ev.Key() {
case tcell.KeyCtrlA:
return Event{CtrlA, 0, nil}
return Event{keyfn('a'), 0, nil}
case tcell.KeyCtrlB:
return Event{CtrlB, 0, nil}
return Event{keyfn('b'), 0, nil}
case tcell.KeyCtrlC:
return Event{CtrlC, 0, nil}
return Event{keyfn('c'), 0, nil}
case tcell.KeyCtrlD:
return Event{CtrlD, 0, nil}
return Event{keyfn('d'), 0, nil}
case tcell.KeyCtrlE:
return Event{CtrlE, 0, nil}
return Event{keyfn('e'), 0, nil}
case tcell.KeyCtrlF:
return Event{CtrlF, 0, nil}
return Event{keyfn('f'), 0, nil}
case tcell.KeyCtrlG:
return Event{CtrlG, 0, nil}
return Event{keyfn('g'), 0, nil}
case tcell.KeyCtrlH:
return Event{keyfn('h'), 0, nil}
case tcell.KeyCtrlI:
return Event{keyfn('i'), 0, nil}
case tcell.KeyCtrlJ:
return Event{CtrlJ, 0, nil}
return Event{keyfn('j'), 0, nil}
case tcell.KeyCtrlK:
return Event{CtrlK, 0, nil}
return Event{keyfn('k'), 0, nil}
case tcell.KeyCtrlL:
return Event{CtrlL, 0, nil}
return Event{keyfn('l'), 0, nil}
case tcell.KeyCtrlM:
if alt {
return Event{AltEnter, 0, nil}
}
return Event{CtrlM, 0, nil}
return Event{keyfn('m'), 0, nil}
case tcell.KeyCtrlN:
return Event{CtrlN, 0, nil}
return Event{keyfn('n'), 0, nil}
case tcell.KeyCtrlO:
return Event{CtrlO, 0, nil}
return Event{keyfn('o'), 0, nil}
case tcell.KeyCtrlP:
return Event{CtrlP, 0, nil}
return Event{keyfn('p'), 0, nil}
case tcell.KeyCtrlQ:
return Event{CtrlQ, 0, nil}
return Event{keyfn('q'), 0, nil}
case tcell.KeyCtrlR:
return Event{CtrlR, 0, nil}
return Event{keyfn('r'), 0, nil}
case tcell.KeyCtrlS:
return Event{CtrlS, 0, nil}
return Event{keyfn('s'), 0, nil}
case tcell.KeyCtrlT:
return Event{CtrlT, 0, nil}
return Event{keyfn('t'), 0, nil}
case tcell.KeyCtrlU:
return Event{CtrlU, 0, nil}
return Event{keyfn('u'), 0, nil}
case tcell.KeyCtrlV:
return Event{CtrlV, 0, nil}
return Event{keyfn('v'), 0, nil}
case tcell.KeyCtrlW:
return Event{CtrlW, 0, nil}
return Event{keyfn('w'), 0, nil}
case tcell.KeyCtrlX:
return Event{CtrlX, 0, nil}
return Event{keyfn('x'), 0, nil}
case tcell.KeyCtrlY:
return Event{CtrlY, 0, nil}
return Event{keyfn('y'), 0, nil}
case tcell.KeyCtrlZ:
return Event{CtrlZ, 0, nil}
return Event{keyfn('z'), 0, nil}
case tcell.KeyCtrlSpace:
return Event{CtrlSpace, 0, nil}
case tcell.KeyBackspace, tcell.KeyBackspace2:

@ -75,7 +75,6 @@ const (
F11
F12
AltEnter
AltSpace
AltSlash
AltBS
@ -90,7 +89,9 @@ const ( // Reset iota
AltD
AltE
AltF
AltZ = AltA + 'z' - 'a'
AltZ = AltA + 'z' - 'a'
CtrlAltA = AltZ + 1
CtrlAltM = CtrlAltA + 'm' - 'a'
)
const (

Loading…
Cancel
Save