mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-12-23 03:19:01 +00:00
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
|
||||||
|
84
fzf
84
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
|
||||||
@ -904,8 +904,10 @@ class FZF
|
|||||||
def start_loop
|
def start_loop
|
||||||
got = nil
|
got = nil
|
||||||
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,6 +960,39 @@ 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|
|
||||||
|
case val
|
||||||
|
when String
|
||||||
|
input.insert cursor, val
|
||||||
|
cursor += val.length
|
||||||
|
when Hash
|
||||||
|
event = val[:event]
|
||||||
|
case event
|
||||||
|
when :click, :release
|
||||||
|
x, y, shift = val.values_at :x, :y, :shift
|
||||||
|
if y == cursor_y
|
||||||
|
cursor = [0, [input.length, x - 2].min].max
|
||||||
|
elsif x > 1 && y <= max_items
|
||||||
|
tv = max_items - y - 1
|
||||||
|
|
||||||
|
case event
|
||||||
|
when :click
|
||||||
|
vselect { |_| tv }
|
||||||
|
actions[ctrl(:i)].call(:sclick) if shift
|
||||||
|
mouse_event.v = tv
|
||||||
|
when :release
|
||||||
|
if !shift && mouse_event.double?(tv)
|
||||||
|
actions[ctrl(:m)].call
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
when :scroll
|
||||||
|
diff, shift = val.values_at :diff, :shift
|
||||||
|
actions[ctrl(:i)].call(:sclick) if shift
|
||||||
|
actions[ctrl(diff > 0 ? :j : :k)].call
|
||||||
|
end
|
||||||
|
end
|
||||||
|
}
|
||||||
}
|
}
|
||||||
actions[ctrl(:p)] = actions[ctrl(:k)]
|
actions[ctrl(:p)] = actions[ctrl(:k)]
|
||||||
actions[ctrl(:n)] = actions[ctrl(:j)]
|
actions[ctrl(:n)] = actions[ctrl(:j)]
|
||||||
@ -960,45 +1001,12 @@ class FZF
|
|||||||
actions[ctrl(:q)] = actions[ctrl(:g)] = actions[ctrl(:c)] = actions[:esc]
|
actions[ctrl(:q)] = actions[ctrl(:g)] = actions[ctrl(:c)] = actions[:esc]
|
||||||
|
|
||||||
emit(:key) { [@query.get, cursor] } unless @query.empty?
|
emit(:key) { [@query.get, cursor] } unless @query.empty?
|
||||||
mouse = MouseEvent.new
|
|
||||||
while true
|
while true
|
||||||
@cursor_x.set cursor
|
@cursor_x.set cursor
|
||||||
render { print_input }
|
render { print_input }
|
||||||
|
|
||||||
if key = get_input(actions)
|
if key = get_input(actions)
|
||||||
upd = actions.fetch(key, proc { |val|
|
upd = actions.fetch(key, actions[:default]).call(key)
|
||||||
case val
|
|
||||||
when String
|
|
||||||
input.insert cursor, val
|
|
||||||
cursor += val.length
|
|
||||||
when Hash
|
|
||||||
event = val[:event]
|
|
||||||
case event
|
|
||||||
when :click, :release
|
|
||||||
x, y, shift = val.values_at :x, :y, :shift
|
|
||||||
if y == cursor_y
|
|
||||||
cursor = [0, [input.length, x - 2].min].max
|
|
||||||
elsif x > 1 && y <= max_items
|
|
||||||
tv = max_items - y - 1
|
|
||||||
|
|
||||||
case event
|
|
||||||
when :click
|
|
||||||
vselect { |_| tv }
|
|
||||||
actions[ctrl(:i)].call(:sclick) if shift
|
|
||||||
mouse.v = tv
|
|
||||||
when :release
|
|
||||||
if !shift && mouse.double?(tv)
|
|
||||||
actions[ctrl(:m)].call
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
when :scroll
|
|
||||||
diff, shift = val.values_at :diff, :shift
|
|
||||||
actions[ctrl(:i)].call(:sclick) if shift
|
|
||||||
actions[ctrl(diff > 0 ? :j : :k)].call
|
|
||||||
end
|
|
||||||
end
|
|
||||||
}).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…
Reference in New Issue
Block a user