Shift-click and wheel

This commit is contained in:
Junegunn Choi 2014-01-30 01:01:31 +09:00
parent 6fb4b6d097
commit aad335475c

37
fzf
View File

@ -7,7 +7,7 @@
# / __/ / /_/ __/ # / __/ / /_/ __/
# /_/ /___/_/ Fuzzy finder for your shell # /_/ /___/_/ Fuzzy finder for your shell
# #
# Version: 0.6.2-devel (January 22, 2014) # Version: 0.7.0-devel (January 30, 2014)
# #
# Author: Junegunn Choi # Author: Junegunn Choi
# URL: https://github.com/junegunn/fzf # URL: https://github.com/junegunn/fzf
@ -472,8 +472,8 @@ class FZF
def init_screen def init_screen
C.init_screen C.init_screen
if ENV.fetch('FZF_MOUSE_ENABLED', '1') == '1' if ENV.fetch('FZF_MOUSE_ENABLED', '1') == '1'
C.mousemask C::BUTTON1_CLICKED | C::BUTTON1_DOUBLE_CLICKED | C.mouseinterval 0
C::BUTTON2_PRESSED | C::BUTTON4_PRESSED C.mousemask C::ALL_MOUSE_EVENTS
end end
C.stdscr.keypad(true) C.stdscr.keypad(true)
C.start_color C.start_color
@ -748,7 +748,13 @@ class FZF
else else
@selects[sel] = 1 @selects[sel] = 1
end end
vselect { |v| v + (o == C::KEY_BTAB ? 1 : -1) } unless o == :select vselect { |v|
v + case o
when :select then 0
when C::KEY_BTAB then 1
else -1
end
}
end end
}, },
ctrl(:b) => proc { cursor = [0, cursor - 1].max; nil }, ctrl(:b) => proc { cursor = [0, cursor - 1].max; nil },
@ -768,6 +774,7 @@ class FZF
actions[:select] = actions[C::KEY_BTAB] = actions[ctrl(:i)] actions[:select] = actions[C::KEY_BTAB] = actions[ctrl(:i)]
emit(:key) { [@query.get, cursor] } unless @query.empty? emit(:key) { [@query.get, cursor] } unless @query.empty?
pmv = nil
while true while true
@cursor_x.set cursor @cursor_x.set cursor
render { print_input } render { print_input }
@ -778,26 +785,28 @@ class FZF
case ch case ch
when C::KEY_MOUSE when C::KEY_MOUSE
if m = C.getmouse if m = C.getmouse
case m.bstate st = m.bstate
when C::BUTTON1_CLICKED if ((st & C::BUTTON1_PRESSED) | (st & C::BUTTON1_RELEASED)) > 0
if m.y == cursor_y if m.y == cursor_y
# TODO Wide-characters # TODO Wide-characters
cursor = [0, [input.length, m.x - 2].min].max cursor = [0, [input.length, m.x - 2].min].max
elsif m.x > 1 && m.y <= max_items elsif m.x > 1 && m.y <= max_items
vselect { |v| vselect { |v|
tv = max_items - m.y - 1 tv = max_items - m.y - 1
ch = :select if v == tv if st & C::BUTTON1_RELEASED > 0
if (st & C::BUTTON_SHIFT) > 0
ch = :select
elsif pmv == tv
ch = ctrl(:m)
end
pmv = tv
end
tv tv
} }
end end
when C::BUTTON1_DOUBLE_CLICKED elsif ((st & 0x8000000) | (st & C::BUTTON2_PRESSED)) > 0
if m.x > 1 && m.x <= max_items
vselect { |v| max_items - m.y - 1 }
ch = ctrl(:m)
end
when 0x8000000, C::BUTTON2_PRESSED
ch = C::KEY_DOWN ch = C::KEY_DOWN
when C::BUTTON4_PRESSED elsif (st & C::BUTTON4_PRESSED) > 0
ch = C::KEY_UP ch = C::KEY_UP
end end
end end