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
|
# /_/ /___/_/ Fuzzy finder for your shell
|
||||||
#
|
#
|
||||||
# Version: 0.8.9 (Dec 23, 2014)
|
# Version: 0.8.9 (Dec 24, 2014)
|
||||||
#
|
#
|
||||||
# Author: Junegunn Choi
|
# Author: Junegunn Choi
|
||||||
# URL: https://github.com/junegunn/fzf
|
# URL: https://github.com/junegunn/fzf
|
||||||
@ -958,7 +958,7 @@ class FZF
|
|||||||
when 'd', 100 then :alt_d
|
when 'd', 100 then :alt_d
|
||||||
when 'f', 102 then :alt_f
|
when 'f', 102 then :alt_f
|
||||||
when :esc then :esc
|
when :esc then :esc
|
||||||
when 127 then ctrl(:w)
|
when 127 then :alt_bs
|
||||||
else next
|
else next
|
||||||
end if ord == 27
|
end if ord == 27
|
||||||
|
|
||||||
@ -1014,13 +1014,21 @@ class FZF
|
|||||||
yanked = ''
|
yanked = ''
|
||||||
mouse_event = MouseEvent.new
|
mouse_event = MouseEvent.new
|
||||||
backword = proc {
|
backword = proc {
|
||||||
cursor = (input[0, cursor].rindex(/\s\S/) || -1) + 1
|
cursor = (input[0, cursor].rindex(/[^[:alnum:]][[:alnum:]]/) || -1) + 1
|
||||||
nil
|
nil
|
||||||
}
|
}
|
||||||
forward = proc {
|
forward = proc {
|
||||||
cursor += (input[cursor..-1].index(/(\S\s)|(.$)/) || -1) + 1
|
cursor += (input[cursor..-1].index(/([[:alnum:]][^[:alnum:]])|(.$)/) || -1) + 1
|
||||||
nil
|
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 = {
|
actions = {
|
||||||
:esc => proc { exit 1 },
|
:esc => proc { exit 1 },
|
||||||
ctrl(:d) => proc {
|
ctrl(:d) => proc {
|
||||||
@ -1043,14 +1051,7 @@ class FZF
|
|||||||
ctrl(:e) => proc { cursor = input.length; nil },
|
ctrl(:e) => proc { cursor = input.length; nil },
|
||||||
ctrl(:j) => proc { vselect { |v| v - @rev_dir } },
|
ctrl(:j) => proc { vselect { |v| v - @rev_dir } },
|
||||||
ctrl(:k) => proc { vselect { |v| v + @rev_dir } },
|
ctrl(:k) => proc { vselect { |v| v + @rev_dir } },
|
||||||
ctrl(:w) => proc {
|
ctrl(:w) => proc { rubout.call /\s\S/ },
|
||||||
pcursor = cursor
|
|
||||||
backword.call
|
|
||||||
if pcursor > cursor
|
|
||||||
yanked = input[cursor...pcursor]
|
|
||||||
input = input[0...cursor] + input[pcursor..-1]
|
|
||||||
end
|
|
||||||
},
|
|
||||||
ctrl(:y) => proc { actions[:default].call yanked },
|
ctrl(:y) => proc { actions[:default].call yanked },
|
||||||
ctrl(:h) => proc { input[cursor -= 1] = '' if cursor > 0 },
|
ctrl(:h) => proc { input[cursor -= 1] = '' if cursor > 0 },
|
||||||
ctrl(:i) => proc { |o|
|
ctrl(:i) => proc { |o|
|
||||||
@ -1075,6 +1076,7 @@ class FZF
|
|||||||
:del => proc { input[cursor] = '' if input.length > cursor },
|
:del => proc { input[cursor] = '' if input.length > cursor },
|
||||||
:pgup => proc { vselect { |v| v + @rev_dir * (max_items - 1) } },
|
:pgup => proc { vselect { |v| v + @rev_dir * (max_items - 1) } },
|
||||||
:pgdn => 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_b => proc { backword.call },
|
||||||
:alt_d => proc {
|
:alt_d => proc {
|
||||||
pcursor = cursor
|
pcursor = cursor
|
||||||
|
@ -822,6 +822,21 @@ class TestFZF < MiniTest::Unit::TestCase
|
|||||||
tty << ctrl(:e) << " = " << ctrl(:y)
|
tty << ctrl(:e) << " = " << ctrl(:y)
|
||||||
tty << "\r"
|
tty << "\r"
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
def alt chr
|
def alt chr
|
||||||
|
Loading…
Reference in New Issue
Block a user