Skip to content
Myr

Improve word motions: ALT-B, ALT-F, ALT-D, ALT-BS (#112)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent 0019067 · Browse files · 2 files+29 added−12 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+29 added−12 removed

  • tests:+15 added−0 removed
  • other:+14 added−12 removed

2 files+29 added−12 removed

modified:test/test_fzf.rb+15 added
820 unmodified lines
821 tty << alt(:b) << alt(127.chr)822 tty << ctrl(:e) << " = " << ctrl(:y)823 tty << "\r"824 end825826 # Word-movements827 assert_fzf_output %w[--print-query], "", "ello!_orld!~ foo=?" do |tty|828 tty << "hello_world==baby?"829 tty << alt(:b) << ctrl(:d)830 tty << alt(:b) << ctrl(:d)831 tty << alt(:b) << ctrl(:d)832 tty << alt(:f) << '!'833 tty << alt(:f) << '!'834 tty << alt(:d) << '~'835 tty << " foo=bar foo=bar"836 tty << ctrl(:w)837 tty << alt(127.chr)838 tty << "\r"839 end840 end841842 def alt chr843 "\e#{chr}"
7 unmodified lines
modified:fzf+14 added-12 removed
5 unmodified lines
6# / /_/_ / / /_7# / __/ / /_/ __/8# /_/ /___/_/ Fuzzy finder for your shell9#10# Version: 0.8.9 (Dec 23, 2014)10# Version: 0.8.9 (Dec 24, 2014)11#12# Author: Junegunn Choi13# URL: https://github.com/junegunn/fzf14# License: MIT
942 unmodified lines
957 when 'b', 98 then :alt_b958 when 'd', 100 then :alt_d959 when 'f', 102 then :alt_f960 when :esc then :esc961 when 127 then ctrl(:w)961 when 127 then :alt_bs962 else next963 end if ord == 27964965 return ord if ord.nil? || ord.is_a?(Hash)
47 unmodified lines
1013 cursor = input.length1014 yanked = ''1015 mouse_event = MouseEvent.new1016 backword = proc {1017 cursor = (input[0, cursor].rindex(/\s\S/) || -1) + 11017 cursor = (input[0, cursor].rindex(/[^[:alnum:]][[:alnum:]]/) || -1) + 11018 nil1019 }1020 forward = proc {1021 cursor += (input[cursor..-1].index(/(\S\s)|(.$)/) || -1) + 11021 cursor += (input[cursor..-1].index(/([[:alnum:]][^[:alnum:]])|(.$)/) || -1) + 11022 nil1023 }1024 rubout = proc { |regex|1025 pcursor = cursor1026 cursor = (input[0, cursor].rindex(regex) || -1) + 11027 if pcursor > cursor1028 yanked = input[cursor...pcursor]1029 input = input[0...cursor] + input[pcursor..-1]1030 end1031 }1032 actions = {1033 :esc => proc { exit 1 },1034 ctrl(:d) => proc {1035 if input.empty?
14 unmodified lines
1050 ctrl(:a) => proc { cursor = 0; nil },1051 ctrl(:e) => proc { cursor = input.length; nil },1052 ctrl(:j) => proc { vselect { |v| v - @rev_dir } },1053 ctrl(:k) => proc { vselect { |v| v + @rev_dir } },1046 ctrl(:w) => proc {1047 pcursor = cursor1048 backword.call1049 if pcursor > cursor1050 yanked = input[cursor...pcursor]1051 input = input[0...cursor] + input[pcursor..-1]1052 end1053 },1054 ctrl(:w) => proc { rubout.call /\s\S/ },1055 ctrl(:y) => proc { actions[:default].call yanked },1056 ctrl(:h) => proc { input[cursor -= 1] = '' if cursor > 0 },1057 ctrl(:i) => proc { |o|1058 if @multi && sel = pick
16 unmodified lines
1075 ctrl(:l) => proc { render { C.clear; C.refresh }; update_list true },1076 :del => proc { input[cursor] = '' if input.length > cursor },1077 :pgup => proc { vselect { |v| v + @rev_dir * (max_items - 1) } },1078 :pgdn => proc { vselect { |v| v - @rev_dir * (max_items - 1) } },1079 :alt_bs => proc { rubout.call /[^[:alnum:]][[:alnum:]]/ },1080 :alt_b => proc { backword.call },1081 :alt_d => proc {1082 pcursor = cursor1083 forward.call
246 unmodified lines