Skip to content
Myr

Implement ALT-B / ALT-F

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

authored by Junegunn Choi · committed by Junegunn Choi · parent 419bc17 · Browse files · 2 files+29 added−15 removed
This commit

State

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

Diff stats

2 files+29 added−15 removed

  • other:+29 added−15 removed

2 files+29 added−15 removed

modified:fzf+28 added-15 removed
8 unmodified lines
9#10# URL: https://github.com/junegunn/fzf11# Author: Junegunn Choi12# License: MIT13# Last update: November 16, 201313# Last update: November 17, 201314#15# Copyright (c) 2013 Junegunn Choi16#17# MIT License
612 unmodified lines
630 begin631 tty = IO.open(IO.sysopen('/dev/tty'), 'r')632 input = ''633 cursor = 0634 backword = proc {635 cursor = (input[0, cursor].rindex(/\s\S/) || -1) + 1636 }637 actions = {638 :nop => proc { nil },639 ctrl(:c) => proc { exit 1 },640 ctrl(:d) => proc { exit 1 if input.empty? },
6 unmodified lines
647 ctrl(:e) => proc { cursor = input.length; nil },648 ctrl(:j) => proc { @vcursor.set { |v| @vcursors << v; v - 1 }; update_list false },649 ctrl(:k) => proc { @vcursor.set { |v| @vcursors << v; v + 1 }; update_list false },650 ctrl(:w) => proc {648 ridx = (input[0...cursor - 1].rindex(/\S\s/) || -2) + 2649 input = input[0...ridx] + input[cursor..-1]650 cursor = ridx651 pcursor = cursor652 backword.call653 input = input[0...cursor] + input[pcursor..-1]654 },655 127 => proc { input[cursor -= 1] = '' if cursor > 0 },656 9 => proc { |o|657 if @multi && sel = pick
10 unmodified lines
668 end669 },670 :left => proc { cursor = [0, cursor - 1].max; nil },671 :right => proc { cursor = [input.length, cursor + 1].min; nil },672 :alt_b => proc { backword.call; nil },673 :alt_f => proc {674 cursor += (input[cursor..-1].index(/(\S\s)|(.$)/) || -1) + 1675 nil676 },677 }678 actions[ctrl(:b)] = actions[:left]679 actions[ctrl(:f)] = actions[:right]680 actions[ctrl(:h)] = actions[127]
5 unmodified lines
686 @cursor_x.set cursor687 render { print_input }688689 ord = tty.getc.ord682 if ord == 27690 ord =691 case ord = tty.getc.ord692 when 91685 ord = case tty.getc.ord686 when 68 then :left687 when 67 then :right688 when 66 then ctrl(:j)689 when 65 then ctrl(:k)690 when 90 then :stab691 else :nop692 end693 end694 end693 case tty.getc.ord694 when 68 then :left695 when 67 then :right696 when 66 then ctrl(:j)697 when 65 then ctrl(:k)698 when 90 then :stab699 else :nop700 end701 when 'b'.ord702 :alt_b703 when 'f'.ord704 :alt_f705 else706 ord707 end if ord == 27708709 upd = actions.fetch(ord, proc { |ord|710 char = [ord].pack('U*')711 if char =~ /[[:print:]]/
138 unmodified lines
modified:README.md+1 added
109 unmodified lines
110111- CTRL-A / CTRL-E112- CTRL-B / CTRL-F113- CTRL-W / CTRL-U114- ALT-B / ALT-F115116If you enable multi-select mode with `-m` option, you can select multiple items117with TAB or Shift-TAB key.118
150 unmodified lines