Skip to content
Myr

Fix handling of arrow keys with alt and/or shift modifier

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix #2254 - Properly handle extra chars in the buffer. Patch suggested by @mckelly2833. - Support alt-arrow sequences in \e[1;3A format - Support shift-alt-arrow sequences in \e[1;10A format

authored by Junegunn Choi · committed by Junegunn Choi · parent 1efef88 · Browse files · 5 files+87 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+87 added−5 removed

  • other:+87 added−5 removed

5 files+87 added−5 removed

modified:man/man1/fzf.1+9 added-1 removed
19 unmodified lines
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN22THE SOFTWARE.23..24.TH fzf 1 "Nov 2020" "fzf 0.24.3" "fzf - a command-line fuzzy finder"24.TH fzf 1 "Nov 2020" "fzf 0.24.4" "fzf - a command-line fuzzy finder"2526.SH NAME27fzf - a command-line fuzzy finder28
682 unmodified lines
711\fIshift-left\fR712.br713\fIshift-right\fR714.br715\fIalt-shift-up\fR716.br717\fIalt-shift-down\fR718.br719\fIalt-shift-left\fR720.br721\fIalt-shift-right\fR722.br723\fIleft-click\fR724.br725\fIright-click\fR726.br
191 unmodified lines
modified:src/tui/light.go+37 added-3 removed
461 unmodified lines
462 }463 }464 return Event{Invalid, 0, nil}465 case ';':466 if len(r.buffer) != 6 {466 if len(r.buffer) < 6 {467 return Event{Invalid, 0, nil}468 }469 *sz = 6470 switch r.buffer[4] {471 case '2', '5':472 switch r.buffer[5] {471 case '1', '2', '3', '5':472 alt := r.buffer[4] == '3'473 altShift := r.buffer[4] == '1' && r.buffer[5] == '0'474 char := r.buffer[5]475 if altShift {476 if len(r.buffer) < 7 {477 return Event{Invalid, 0, nil}478 }479 *sz = 7480 char = r.buffer[6]481 }482 switch char {483 case 'A':484 if alt {485 return Event{AltUp, 0, nil}486 }487 if altShift {488 return Event{AltSUp, 0, nil}489 }490 return Event{SUp, 0, nil}491 case 'B':492 if alt {493 return Event{AltDown, 0, nil}494 }495 if altShift {496 return Event{AltSDown, 0, nil}497 }498 return Event{SDown, 0, nil}499 case 'C':500 if alt {501 return Event{AltRight, 0, nil}502 }503 if altShift {504 return Event{AltSRight, 0, nil}505 }506 return Event{SRight, 0, nil}507 case 'D':508 if alt {509 return Event{AltLeft, 0, nil}510 }511 if altShift {512 return Event{AltSLeft, 0, nil}513 }514 return Event{SLeft, 0, nil}515 }516 } // r.buffer[4]517 } // r.buffer[3]
462 unmodified lines
modified:src/tui/tcell.go+28 added-1 removed
220 unmodified lines
221 }222223 // process keyboard:224 case *tcell.EventKey:225 mods := ev.Modifiers()225 alt := (ev.Modifiers() & tcell.ModAlt) > 0226 alt := (mods & tcell.ModAlt) > 0227 shift := (mods & tcell.ModShift) > 0228 altShift := alt && shift229 keyfn := func(r rune) int {230 if alt {231 return CtrlAltA - 'a' + int(r)232 }
66 unmodified lines
299 }300 return Event{BSpace, 0, nil}301302 case tcell.KeyUp:303 if altShift {304 return Event{AltSUp, 0, nil}305 }306 if shift {307 return Event{SUp, 0, nil}308 }309 if alt {310 return Event{AltUp, 0, nil}311 }312 return Event{Up, 0, nil}313 case tcell.KeyDown:314 if altShift {315 return Event{AltSDown, 0, nil}316 }317 if shift {318 return Event{SDown, 0, nil}319 }320 if alt {321 return Event{AltDown, 0, nil}322 }323 return Event{Down, 0, nil}324 case tcell.KeyLeft:325 if altShift {326 return Event{AltSLeft, 0, nil}327 }328 if shift {329 return Event{SLeft, 0, nil}330 }331 if alt {332 return Event{AltLeft, 0, nil}333 }334 return Event{Left, 0, nil}335 case tcell.KeyRight:336 if altShift {337 return Event{AltSRight, 0, nil}338 }339 if shift {340 return Event{SRight, 0, nil}341 }342 if alt {343 return Event{AltRight, 0, nil}344 }345 return Event{Right, 0, nil}
320 unmodified lines
modified:src/tui/tui.go+5 added
96 unmodified lines
97 AltDown98 AltLeft99 AltRight100101 AltSUp102 AltSDown103 AltSLeft104 AltSRight105106 Alt0107)108109const ( // Reset iota
480 unmodified lines
modified:src/options.go+8 added
522 unmodified lines
523 case "pgup", "page-up":524 chord = tui.PgUp525 case "pgdn", "page-down":526 chord = tui.PgDn527 case "alt-shift-up", "shift-alt-up":528 chord = tui.AltSUp529 case "alt-shift-down", "shift-alt-down":530 chord = tui.AltSDown531 case "alt-shift-left", "shift-alt-left":532 chord = tui.AltSLeft533 case "alt-shift-right", "shift-alt-right":534 chord = tui.AltSRight535 case "shift-up":536 chord = tui.SUp537 case "shift-down":538 chord = tui.SDown
1029 unmodified lines