Skip to content
Myr

Add support for ALT-D and ALT-BS key bindings

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

https://github.com/junegunn/fzf/issues/111#issuecomment-67832143

authored by Junegunn Choi · committed by Junegunn Choi · parent d38f7a5 · Browse files · 2 files+48 added−6 removed
This commit

State

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

Trailers

  • https: //github.com/junegunn/fzf/issues/111#issuecomment-67832143

Diff stats

2 files+48 added−6 removed

  • tests:+25 added−0 removed
  • other:+23 added−6 removed

2 files+48 added−6 removed

modified:test/test_fzf.rb+25 added
48 unmodified lines
49 @mutex.synchronize do50 @buffer << str51 @condv.broadcast52 end53 self54 end55end5657class TestFZF < MiniTest::Unit::TestCase
747 unmodified lines
805 assert_fzf_output %w[-m --with-nth=2,1], lines, lines do |tty|806 tty << "\e[Z\e[Z"807 tty << "\r"808 end809810 # ALT-D811 assert_fzf_output %w[--print-query], "", "hello baby = world" do |tty|812 tty << "hello world baby"813 tty << alt(:b) << alt(:b) << alt(:d)814 tty << ctrl(:e) << " = " << ctrl(:y)815 tty << "\r"816 end817818 # ALT-BACKSPACE819 assert_fzf_output %w[--print-query], "", "hello baby = world " do |tty|820 tty << "hello world baby"821 tty << alt(:b) << alt(127.chr)822 tty << ctrl(:e) << " = " << ctrl(:y)823 tty << "\r"824 end825 end826827 def alt chr828 "\e#{chr}"829 end830831 def ctrl char832 char.to_s.ord - 'a'.ord + 1833 end834end835
modified:fzf+23 added-6 removed
5 unmodified lines
6# / /_/_ / / /_7# / __/ / /_/ __/8# /_/ /___/_/ Fuzzy finder for your shell9#10# Version: 0.8.8 (Nov 4, 2014)10# Version: 0.8.9 (Dec 23, 2014)11#12# Author: Junegunn Choi13# URL: https://github.com/junegunn/fzf14# License: MIT
939 unmodified lines
954 when 77955 get_mouse956 end957 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)962 else next963 end if ord == 27964965 return ord if ord.nil? || ord.is_a?(Hash)
48 unmodified lines
1014 yanked = ''1015 mouse_event = MouseEvent.new1016 backword = proc {1017 cursor = (input[0, cursor].rindex(/\s\S/) || -1) + 11018 nil1019 }1020 forward = proc {1021 cursor += (input[cursor..-1].index(/(\S\s)|(.$)/) || -1) + 11022 nil1023 }1024 actions = {1025 :esc => proc { exit 1 },1026 ctrl(:d) => proc {1027 if input.empty?
17 unmodified lines
1045 ctrl(:k) => proc { vselect { |v| v + @rev_dir } },1046 ctrl(:w) => proc {1047 pcursor = cursor1048 backword.call1049 if pcursor > cursor1042 yanked = input[cursor...pcursor] if pcursor > cursor1043 input = input[0...cursor] + input[pcursor..-1]1050 yanked = input[cursor...pcursor]1051 input = input[0...cursor] + input[pcursor..-1]1052 end1053 },1054 ctrl(:y) => proc { actions[:default].call yanked },1055 ctrl(:h) => proc { input[cursor -= 1] = '' if cursor > 0 },1056 ctrl(:i) => proc { |o|
17 unmodified lines
1074 ctrl(:l) => proc { render { C.clear; C.refresh }; update_list true },1075 :del => proc { input[cursor] = '' if input.length > cursor },1076 :pgup => proc { vselect { |v| v + @rev_dir * (max_items - 1) } },1077 :pgdn => proc { vselect { |v| v - @rev_dir * (max_items - 1) } },1069 :alt_b => proc { backword.call; nil },1078 :alt_b => proc { backword.call },1079 :alt_d => proc {1080 pcursor = cursor1081 forward.call1082 if cursor > pcursor1083 yanked = input[pcursor...cursor]1084 input = input[0...pcursor] + input[cursor..-1]1085 cursor = pcursor1086 end1087 },1088 :alt_f => proc {1071 cursor += (input[cursor..-1].index(/(\S\s)|(.$)/) || -1) + 11072 nil1089 forward.call1090 },1091 :default => proc { |val|1092 case val1093 when String
234 unmodified lines