Class: EasyJump
- Inherits:
-
Object
- Object
- EasyJump
- Defined in:
- lib/vimamsa/easy_jump.rb
Overview
Similar feature as Vim EasyMotion github.com/easymotion/vim-easymotion
Class Method Summary collapse
-
.start ⇒ Object
def self.initialize() make_jump_sequence end.
Instance Method Summary collapse
- #easy_jump_draw ⇒ Object
- #easy_jump_input_char(c, event_type) ⇒ Object
-
#initialize ⇒ EasyJump
constructor
A new instance of EasyJump.
- #make_jump_sequence(num_items) ⇒ Object
Constructor Details
#initialize ⇒ EasyJump
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/vimamsa/easy_jump.rb', line 11 def initialize() # message "EASY JUMP" visible_range = get_visible_area() visible_text = buf[visible_range[0]..visible_range[1]] wsmarks = scan_word_start_marks(visible_text) line_starts = scan_indexes(visible_text, /^/) lsh = Hash[line_starts.collect { |x| [x, true] }] wsmh = Hash[wsmarks.collect { |x| [x, true] }] wsmarks.select! { |x| r = true r = false if lsh[x] or lsh[x - 1] or lsh[x - 2] r } linestart_buf = (line_starts).collect { |x| x + visible_range[0] } wsmarks_buf = (wsmarks).collect { |x| x + visible_range[0] } # All line starts should be accessible with just two key presses, so put them first in order # Other word start positions ordered by distance from current pos wsmarks_buf.sort_by! { |x| (x - buf.pos).abs } @easy_jump_wsmarks = linestart_buf + wsmarks_buf @jump_sequence = make_jump_sequence(@easy_jump_wsmarks.size) vma.kbd.set_keyhandling_override(self.method(:easy_jump_input_char)) @easy_jump_input = "" easy_jump_draw end |
Class Method Details
.start ⇒ Object
def self.initialize() make_jump_sequence end
7 8 9 |
# File 'lib/vimamsa/easy_jump.rb', line 7 def self.start() @@cur = EasyJump.new end |
Instance Method Details
#easy_jump_draw ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/vimamsa/easy_jump.rb', line 65 def easy_jump_draw() # puts @jump_sequence.inspect # puts @easy_jump_wsmarks.inspect vma.gui. for i in 0..(@easy_jump_wsmarks.size - 1) vma.gui.(@jump_sequence[i], @easy_jump_wsmarks[i]) end vma.gui. return return if @jump_sequence.empty? puts "EASY JUMP DRAW" screen_cord = cpp_function_wrapper(0, [@easy_jump_wsmarks]) screen_cord = screen_cord[1..@jump_sequence.size] screen_cord.each_with_index { |point, i| mark_str = @jump_sequence[i] #puts "draw #{point[0]}x#{point[1]}" draw_text(mark_str, point[0] + 3, point[1]) #break if m > @cpos } end |
#easy_jump_input_char(c, event_type) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/vimamsa/easy_jump.rb', line 41 def easy_jump_input_char(c, event_type) return true if event_type != :key_press # vma.paint_stack = [] puts "EASY JUMP: easy_jump_input_char [#{c}]" @easy_jump_input << c.upcase if @jump_sequence.include?(@easy_jump_input) jshash = Hash[@jump_sequence.map.with_index.to_a] nthword = jshash[@easy_jump_input] puts "nthword:#{nthword} #{[@easy_jump_wsmarks[nthword], @jump_sequence[nthword]]}" buf.set_pos(@easy_jump_wsmarks[nthword]) # @kbd.set_mode(:command) vma.kbd.remove_keyhandling_override @jump_sequence = [] vma.gui.() end if @easy_jump_input.size > 2 # @kbd.set_mode(:command) vma.kbd.remove_keyhandling_override @jump_sequence = [] vma.gui.() end return true end |
#make_jump_sequence(num_items) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/vimamsa/easy_jump.rb', line 87 def make_jump_sequence(num_items) left_hand = "asdfvgbqwertzxc123".upcase.split("") right_hand = "jklhnnmyuiop890".upcase.split("") sequence = [] left_hand_fast = "asdf".upcase.split("") right_hand_fast = "jkl;".upcase.split("") left_hand_slow = "wergc".upcase.split("") # v right_hand_slow = "uiophnm,".upcase.split("") left_hand_slow2 = "tzx23".upcase.split("") right_hand_slow2 = "yb9'".upcase.split("") # Rmoved characters that can be mixed: O0Q, 8B, I1, VY left_fast_slow = Array.new(left_hand_fast).concat(left_hand_slow) right_fast_slow = Array.new(right_hand_fast).concat(right_hand_slow) left_hand_all = Array.new(left_hand_fast).concat(left_hand_slow).concat(left_hand_slow2) right_hand_all = Array.new(right_hand_fast).concat(right_hand_slow).concat(right_hand_slow2) left_hand_fast.each { |x| left_hand_fast.each { |y| sequence << "#{x}#{y}" } } right_hand_fast.each { |x| right_hand_fast.each { |y| sequence << "#{x}#{y}" } } right_hand_fast.each { |x| left_hand_fast.each { |y| sequence << "#{x}#{y}" } } left_hand_fast.each { |x| right_hand_fast.each { |y| sequence << "#{x}#{y}" } } left_hand_slow.each { |x| right_fast_slow.each { |y| sequence << "#{x}#{y}" } } right_hand_slow.each { |x| left_fast_slow.each { |y| sequence << "#{x}#{y}" } } left_hand_slow2.each { |x| right_hand_all.each { |y| left_hand_all.each { |z| sequence << "#{x}#{y}#{z}" } } } right_hand_slow2.each { |x| left_hand_all.each { |y| right_hand_all.each { |z| sequence << "#{x}#{y}#{z}" } } } #printf("Size of sequence: %d\n",sequence.size) #puts sequence.inspect return sequence end |