Implement C-Y (yank)
This commit is contained in:
parent
1ba50eba98
commit
5c71ecb267
@ -89,7 +89,7 @@ If you want to preserve the exact sequence of the input, provide `--no-sort` (or
|
|||||||
history | fzf +s
|
history | fzf +s
|
||||||
```
|
```
|
||||||
|
|
||||||
### Key binding
|
### Keys
|
||||||
|
|
||||||
Use CTRL-J and CTRL-K (or CTRL-N and CTRL-P) to change the selection, press
|
Use CTRL-J and CTRL-K (or CTRL-N and CTRL-P) to change the selection, press
|
||||||
enter key to select the item. CTRL-C, CTRL-G, or ESC will terminate the finder.
|
enter key to select the item. CTRL-C, CTRL-G, or ESC will terminate the finder.
|
||||||
@ -98,7 +98,7 @@ The following readline key bindings should also work as expected.
|
|||||||
|
|
||||||
- CTRL-A / CTRL-E
|
- CTRL-A / CTRL-E
|
||||||
- CTRL-B / CTRL-F
|
- CTRL-B / CTRL-F
|
||||||
- CTRL-W / CTRL-U
|
- CTRL-W / CTRL-U / CTRL-Y
|
||||||
- ALT-B / ALT-F
|
- ALT-B / ALT-F
|
||||||
|
|
||||||
If you enable multi-select mode with `-m` option, you can select multiple items
|
If you enable multi-select mode with `-m` option, you can select multiple items
|
||||||
|
48
fzf
48
fzf
@ -7,7 +7,7 @@
|
|||||||
# / __/ / /_/ __/
|
# / __/ / /_/ __/
|
||||||
# /_/ /___/_/ Fuzzy finder for your shell
|
# /_/ /___/_/ Fuzzy finder for your shell
|
||||||
#
|
#
|
||||||
# Version: 0.8.1 (March 9, 2014)
|
# Version: 0.8.2 (March 15, 2014)
|
||||||
#
|
#
|
||||||
# Author: Junegunn Choi
|
# Author: Junegunn Choi
|
||||||
# URL: https://github.com/junegunn/fzf
|
# URL: https://github.com/junegunn/fzf
|
||||||
@ -906,6 +906,8 @@ class FZF
|
|||||||
begin
|
begin
|
||||||
input = @query.get.dup
|
input = @query.get.dup
|
||||||
cursor = input.length
|
cursor = input.length
|
||||||
|
yanked = ''
|
||||||
|
mouse_event = MouseEvent.new
|
||||||
backword = proc {
|
backword = proc {
|
||||||
cursor = (input[0, cursor].rindex(/\s\S/) || -1) + 1
|
cursor = (input[0, cursor].rindex(/\s\S/) || -1) + 1
|
||||||
}
|
}
|
||||||
@ -916,7 +918,11 @@ class FZF
|
|||||||
got = pick
|
got = pick
|
||||||
exit 0
|
exit 0
|
||||||
},
|
},
|
||||||
ctrl(:u) => proc { input = input[cursor..-1]; cursor = 0 },
|
ctrl(:u) => proc {
|
||||||
|
yanked = input[0...cursor] if cursor > 0
|
||||||
|
input = input[cursor..-1]
|
||||||
|
cursor = 0
|
||||||
|
},
|
||||||
ctrl(:a) => proc { cursor = 0; nil },
|
ctrl(:a) => proc { cursor = 0; nil },
|
||||||
ctrl(:e) => proc { cursor = input.length; nil },
|
ctrl(:e) => proc { cursor = input.length; nil },
|
||||||
ctrl(:j) => proc { vselect { |v| v - 1 } },
|
ctrl(:j) => proc { vselect { |v| v - 1 } },
|
||||||
@ -924,8 +930,10 @@ class FZF
|
|||||||
ctrl(:w) => proc {
|
ctrl(:w) => proc {
|
||||||
pcursor = cursor
|
pcursor = cursor
|
||||||
backword.call
|
backword.call
|
||||||
|
yanked = input[cursor...pcursor] if pcursor > cursor
|
||||||
input = input[0...cursor] + input[pcursor..-1]
|
input = input[0...cursor] + input[pcursor..-1]
|
||||||
},
|
},
|
||||||
|
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|
|
||||||
if @multi && sel = pick
|
if @multi && sel = pick
|
||||||
@ -952,21 +960,7 @@ class FZF
|
|||||||
cursor += (input[cursor..-1].index(/(\S\s)|(.$)/) || -1) + 1
|
cursor += (input[cursor..-1].index(/(\S\s)|(.$)/) || -1) + 1
|
||||||
nil
|
nil
|
||||||
},
|
},
|
||||||
}
|
:default => proc { |val|
|
||||||
actions[ctrl(:p)] = actions[ctrl(:k)]
|
|
||||||
actions[ctrl(:n)] = actions[ctrl(:j)]
|
|
||||||
actions[:stab] = actions[ctrl(:i)]
|
|
||||||
actions[127] = actions[ctrl(:h)]
|
|
||||||
actions[ctrl(:q)] = actions[ctrl(:g)] = actions[ctrl(:c)] = actions[:esc]
|
|
||||||
|
|
||||||
emit(:key) { [@query.get, cursor] } unless @query.empty?
|
|
||||||
mouse = MouseEvent.new
|
|
||||||
while true
|
|
||||||
@cursor_x.set cursor
|
|
||||||
render { print_input }
|
|
||||||
|
|
||||||
if key = get_input(actions)
|
|
||||||
upd = actions.fetch(key, proc { |val|
|
|
||||||
case val
|
case val
|
||||||
when String
|
when String
|
||||||
input.insert cursor, val
|
input.insert cursor, val
|
||||||
@ -985,9 +979,9 @@ class FZF
|
|||||||
when :click
|
when :click
|
||||||
vselect { |_| tv }
|
vselect { |_| tv }
|
||||||
actions[ctrl(:i)].call(:sclick) if shift
|
actions[ctrl(:i)].call(:sclick) if shift
|
||||||
mouse.v = tv
|
mouse_event.v = tv
|
||||||
when :release
|
when :release
|
||||||
if !shift && mouse.double?(tv)
|
if !shift && mouse_event.double?(tv)
|
||||||
actions[ctrl(:m)].call
|
actions[ctrl(:m)].call
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -998,7 +992,21 @@ class FZF
|
|||||||
actions[ctrl(diff > 0 ? :j : :k)].call
|
actions[ctrl(diff > 0 ? :j : :k)].call
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
}).call(key)
|
}
|
||||||
|
}
|
||||||
|
actions[ctrl(:p)] = actions[ctrl(:k)]
|
||||||
|
actions[ctrl(:n)] = actions[ctrl(:j)]
|
||||||
|
actions[:stab] = actions[ctrl(:i)]
|
||||||
|
actions[127] = actions[ctrl(:h)]
|
||||||
|
actions[ctrl(:q)] = actions[ctrl(:g)] = actions[ctrl(:c)] = actions[:esc]
|
||||||
|
|
||||||
|
emit(:key) { [@query.get, cursor] } unless @query.empty?
|
||||||
|
while true
|
||||||
|
@cursor_x.set cursor
|
||||||
|
render { print_input }
|
||||||
|
|
||||||
|
if key = get_input(actions)
|
||||||
|
upd = actions.fetch(key, actions[:default]).call(key)
|
||||||
|
|
||||||
# Dispatch key event
|
# Dispatch key event
|
||||||
emit(:key) { [@query.set(input.dup), cursor] } if upd
|
emit(:key) { [@query.set(input.dup), cursor] } if upd
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
Gem::Specification.new do |spec|
|
Gem::Specification.new do |spec|
|
||||||
spec.name = 'fzf'
|
spec.name = 'fzf'
|
||||||
spec.version = '0.8.1'
|
spec.version = '0.8.2'
|
||||||
spec.authors = ['Junegunn Choi']
|
spec.authors = ['Junegunn Choi']
|
||||||
spec.email = ['junegunn.c@gmail.com']
|
spec.email = ['junegunn.c@gmail.com']
|
||||||
spec.description = %q{Fuzzy finder for your shell}
|
spec.description = %q{Fuzzy finder for your shell}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user