Add support for alt-{up,down,left,right} keys

Close #1234
This commit is contained in:
Junegunn Choi 2018-04-12 17:39:28 +09:00
parent 7add75126d
commit 7dbbbef51a
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
5 changed files with 48 additions and 1 deletions

View File

@ -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 "Feb 2018" "fzf 0.17.4-devel" "fzf - a command-line fuzzy finder"
.TH fzf 1 "Apr 2018" "fzf 0.17.4-devel" "fzf - a command-line fuzzy finder"
.SH NAME
fzf - a command-line fuzzy finder
@ -464,6 +464,10 @@ e.g. \fBfzf --bind=ctrl-j:accept,ctrl-k:kill-line\fR
\fIenter\fR (\fIreturn\fR \fIctrl-m\fR)
\fIspace\fR
\fIbspace\fR (\fIbs\fR)
\fIalt-up\fR
\fIalt-down\fR
\fIalt-left\fR
\fIalt-right\fR
\fIalt-enter\fR
\fIalt-space\fR
\fIalt-bspace\fR (\fIalt-bs\fR)

View File

@ -410,6 +410,14 @@ func parseKeyChords(str string, message string) map[int]string {
chord = tui.AltSlash
case "alt-bs", "alt-bspace":
chord = tui.AltBS
case "alt-up":
chord = tui.AltUp
case "alt-down":
chord = tui.AltDown
case "alt-left":
chord = tui.AltLeft
case "alt-right":
chord = tui.AltRight
case "tab":
chord = tui.Tab
case "btab", "shift-tab":

View File

@ -360,6 +360,11 @@ func (r *LightRenderer) escSequence(sz *int) Event {
if r.buffer[1] >= 1 && r.buffer[1] <= 'z'-'a'+1 {
return Event{int(CtrlAltA + r.buffer[1] - 1), 0, nil}
}
alt := false
if len(r.buffer) > 2 && r.buffer[1] == ESC {
r.buffer = r.buffer[1:]
alt = true
}
switch r.buffer[1] {
case 32:
return Event{AltSpace, 0, nil}
@ -380,12 +385,25 @@ func (r *LightRenderer) escSequence(sz *int) Event {
*sz = 3
switch r.buffer[2] {
case 68:
if alt {
return Event{AltLeft, 0, nil}
}
return Event{Left, 0, nil}
case 67:
if alt {
// Ugh..
return Event{AltRight, 0, nil}
}
return Event{Right, 0, nil}
case 66:
if alt {
return Event{AltDown, 0, nil}
}
return Event{Down, 0, nil}
case 65:
if alt {
return Event{AltUp, 0, nil}
}
return Event{Up, 0, nil}
case 90:
return Event{BTab, 0, nil}

View File

@ -295,12 +295,24 @@ func (r *FullscreenRenderer) GetChar() Event {
return Event{BSpace, 0, nil}
case tcell.KeyUp:
if alt {
return Event{AltUp, 0, nil}
}
return Event{Up, 0, nil}
case tcell.KeyDown:
if alt {
return Event{AltDown, 0, nil}
}
return Event{Down, 0, nil}
case tcell.KeyLeft:
if alt {
return Event{AltLeft, 0, nil}
}
return Event{Left, 0, nil}
case tcell.KeyRight:
if alt {
return Event{AltRight, 0, nil}
}
return Event{Right, 0, nil}
case tcell.KeyHome:

View File

@ -85,6 +85,11 @@ const (
AltSlash
AltBS
AltUp
AltDown
AltLeft
AltRight
Alt0
)