mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-11-22 12:55:17 +00:00
Improve word motions: ALT-B, ALT-F, ALT-D, ALT-BS (#112)
This commit is contained in:
parent
00190677d4
commit
ec040d82dd
26
fzf
26
fzf
@ -7,7 +7,7 @@
|
||||
# / __/ / /_/ __/
|
||||
# /_/ /___/_/ Fuzzy finder for your shell
|
||||
#
|
||||
# Version: 0.8.9 (Dec 23, 2014)
|
||||
# Version: 0.8.9 (Dec 24, 2014)
|
||||
#
|
||||
# Author: Junegunn Choi
|
||||
# URL: https://github.com/junegunn/fzf
|
||||
@ -958,7 +958,7 @@ class FZF
|
||||
when 'd', 100 then :alt_d
|
||||
when 'f', 102 then :alt_f
|
||||
when :esc then :esc
|
||||
when 127 then ctrl(:w)
|
||||
when 127 then :alt_bs
|
||||
else next
|
||||
end if ord == 27
|
||||
|
||||
@ -1014,13 +1014,21 @@ class FZF
|
||||
yanked = ''
|
||||
mouse_event = MouseEvent.new
|
||||
backword = proc {
|
||||
cursor = (input[0, cursor].rindex(/\s\S/) || -1) + 1
|
||||
cursor = (input[0, cursor].rindex(/[^[:alnum:]][[:alnum:]]/) || -1) + 1
|
||||
nil
|
||||
}
|
||||
forward = proc {
|
||||
cursor += (input[cursor..-1].index(/(\S\s)|(.$)/) || -1) + 1
|
||||
cursor += (input[cursor..-1].index(/([[:alnum:]][^[:alnum:]])|(.$)/) || -1) + 1
|
||||
nil
|
||||
}
|
||||
rubout = proc { |regex|
|
||||
pcursor = cursor
|
||||
cursor = (input[0, cursor].rindex(regex) || -1) + 1
|
||||
if pcursor > cursor
|
||||
yanked = input[cursor...pcursor]
|
||||
input = input[0...cursor] + input[pcursor..-1]
|
||||
end
|
||||
}
|
||||
actions = {
|
||||
:esc => proc { exit 1 },
|
||||
ctrl(:d) => proc {
|
||||
@ -1043,14 +1051,7 @@ class FZF
|
||||
ctrl(:e) => proc { cursor = input.length; nil },
|
||||
ctrl(:j) => proc { vselect { |v| v - @rev_dir } },
|
||||
ctrl(:k) => proc { vselect { |v| v + @rev_dir } },
|
||||
ctrl(:w) => proc {
|
||||
pcursor = cursor
|
||||
backword.call
|
||||
if pcursor > cursor
|
||||
yanked = input[cursor...pcursor]
|
||||
input = input[0...cursor] + input[pcursor..-1]
|
||||
end
|
||||
},
|
||||
ctrl(:w) => proc { rubout.call /\s\S/ },
|
||||
ctrl(:y) => proc { actions[:default].call yanked },
|
||||
ctrl(:h) => proc { input[cursor -= 1] = '' if cursor > 0 },
|
||||
ctrl(:i) => proc { |o|
|
||||
@ -1075,6 +1076,7 @@ class FZF
|
||||
:del => proc { input[cursor] = '' if input.length > cursor },
|
||||
:pgup => proc { vselect { |v| v + @rev_dir * (max_items - 1) } },
|
||||
:pgdn => proc { vselect { |v| v - @rev_dir * (max_items - 1) } },
|
||||
:alt_bs => proc { rubout.call /[^[:alnum:]][[:alnum:]]/ },
|
||||
:alt_b => proc { backword.call },
|
||||
:alt_d => proc {
|
||||
pcursor = cursor
|
||||
|
@ -822,6 +822,21 @@ class TestFZF < MiniTest::Unit::TestCase
|
||||
tty << ctrl(:e) << " = " << ctrl(:y)
|
||||
tty << "\r"
|
||||
end
|
||||
|
||||
# Word-movements
|
||||
assert_fzf_output %w[--print-query], "", "ello!_orld!~ foo=?" do |tty|
|
||||
tty << "hello_world==baby?"
|
||||
tty << alt(:b) << ctrl(:d)
|
||||
tty << alt(:b) << ctrl(:d)
|
||||
tty << alt(:b) << ctrl(:d)
|
||||
tty << alt(:f) << '!'
|
||||
tty << alt(:f) << '!'
|
||||
tty << alt(:d) << '~'
|
||||
tty << " foo=bar foo=bar"
|
||||
tty << ctrl(:w)
|
||||
tty << alt(127.chr)
|
||||
tty << "\r"
|
||||
end
|
||||
end
|
||||
|
||||
def alt chr
|
||||
|
Loading…
Reference in New Issue
Block a user