yap-rawline 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e7e26721726b5b17c08f75808f5ecec3973f372d
4
- data.tar.gz: 0447b1df3bb95f8af568416037514e16f4ca78c0
3
+ metadata.gz: ce2b5e0011a3641eea68691491f1e0b5e81344ea
4
+ data.tar.gz: aba178fb5a2528664eb9447e3138b51b85fa392c
5
5
  SHA512:
6
- metadata.gz: 666f67533fc55e170cb5831c96fb11160dd7fd0ea80b196ab385f37f2fc382c386b61a213a01e8bb20bee03a5c0a7e08b8e3697ce1cb6f7a2bb29dc94ea9b152
7
- data.tar.gz: 21a383d655e8d302133603fa727a6ebf7f0580f66376a1aa379bcb0404bfec147db52aa4e45da87bdace60f2ec9032c6d298f9144fb31e18d380d18c7a5f9e67
6
+ metadata.gz: c323b27b18f30f62f19124d58a8b9005f003c70c732298d5bdafb999e7ce1ec24954a077e0205b48f0eda181d40f0ff74cbc24eb03d14ee9a22c7816d783e38b
7
+ data.tar.gz: ee29e835913c429fcf8399fd00fae9d65cc566df6b6d5805e782db0cc271875d7e051cbc76bde2914b7b6d0bc7191e3baf68335f9124cff16c29527fb51a2822
@@ -28,64 +28,107 @@ module RawLine
28
28
  # E.g. holding down the tab key or arrow keys
29
29
  bytes = bytes.uniq
30
30
 
31
- if bytes.map(&:ord) == @keys[:left_arrow]
32
- @completion_matches.forward
33
- match = @completion_matches.get
34
- @completion_found_proc.call(completion: match, possible_completions: @completion_matches.reverse)
35
- elsif bytes.map(&:ord) == @keys[:right_arrow]
36
- @completion_matches.back
37
- match = @completion_matches.get
38
- @completion_found_proc.call(completion: match, possible_completions: @completion_matches.reverse)
39
- elsif bytes.map(&:ord) != @completion_char
40
- @done_proc.call(bytes)
41
- elsif @first_time
42
- unless !@completion_proc || @completion_proc == []
43
- word = @line.text[@line.word[:start]..@line.position-1] || ""
44
- words = @line.text
45
- .split(/\s+/)
46
- .delete_if(&:empty?)
47
- word_index = words.index(word)
48
- Treefell['editor'].puts "completer, looking for completions word=#{word.inspect} words=#{words.inspect} word_index=#{word_index}"
49
- matches = @completion_proc.call(
50
- word,
51
- words,
52
- word_index
53
- )
54
- end
55
- matches = matches.to_a.compact.sort.reverse
56
-
57
- if matches.any?
58
- @completion_matches.resize(matches.length)
59
- matches.each { |w| @completion_matches << w }
60
- end
31
+ if @first_time
32
+ matches = fetch_completions
33
+ resize(matches)
61
34
 
62
35
  if matches.length == 1
63
- Treefell['editor'].puts "completer, exactly one possible completion found: #{matches.inspect}"
64
- @completion_selected_proc.call(@completion_matches.first)
65
- @done_proc.call
36
+ handle_one_match
66
37
  elsif matches.length > 1
67
- Treefell['editor'].puts "completer, more than one possible completion found: #{matches.inspect}"
68
-
69
- # Get first match
70
- @completion_matches.back
71
- match = @completion_matches.get
72
-
73
- # completion matches is a history implementation and its in reverse order from what
74
- # a user would expect
75
- @completion_found_proc.call(completion: match, possible_completions: @completion_matches.reverse)
38
+ handle_more_than_one_match
76
39
  else
77
- Treefell['editor'].puts "completer, no possible completions found"
78
- @completion_not_found_proc.call
79
- @done_proc.call
40
+ handle_no_completions
80
41
  end
42
+
81
43
  @first_time = false
44
+ elsif bytes.map(&:ord) == @keys[:left_arrow]
45
+ select_previous
46
+ elsif bytes.map(&:ord) == @keys[:right_arrow]
47
+ select_next
48
+ elsif bytes.map(&:ord) == @completion_char
49
+ select_next
82
50
  else
83
- @completion_matches.back
84
- match = @completion_matches.get
51
+ Treefell['editor'].puts "completer, done with leftover bytes: #{bytes.inspect}"
52
+ @done_proc.call(bytes)
53
+ end
54
+ end
85
55
 
86
- @completion_found_proc.call(completion: match, possible_completions: @completion_matches.reverse)
56
+ private
57
+
58
+ def fetch_completions
59
+ if @completion_proc && @completion_proc.respond_to?(:call)
60
+ word = @line.text[@line.word[:start]..@line.position-1] || ""
61
+ words = @line.text
62
+ .split(/\s+/)
63
+ .delete_if(&:empty?)
64
+ word_index = words.index(word)
65
+ Treefell['editor'].puts "completer, looking for completions word=#{word.inspect} words=#{words.inspect} word_index=#{word_index}"
66
+ matches = @completion_proc.call(
67
+ word,
68
+ words,
69
+ word_index
70
+ )
87
71
  end
72
+
73
+ # Always return an array so the caller doesn't have
74
+ # to worry about nil
75
+ matches.to_a.compact
76
+ end
77
+
78
+ def handle_one_match
79
+ Treefell['editor'].puts "completer, exactly one possible completion found: #{matches.inspect}"
80
+ @completion_selected_proc.call(@completion_matches.first)
81
+
82
+ Treefell['editor'].puts "completer, done"
83
+ @done_proc.call
88
84
  end
89
- end
90
85
 
86
+ def handle_more_than_one_match
87
+ Treefell['editor'].puts "completer, more than one possible completion"
88
+
89
+ # Get first match
90
+ @completion_matches.back
91
+ match = @completion_matches.get
92
+
93
+ Treefell['editor'].puts "completer: first completion: #{match} possible: #{possible_completions.inspect}"
94
+ @completion_found_proc.call(completion: match, possible_completions: possible_completions)
95
+ end
96
+
97
+ def handle_no_completions
98
+ Treefell['editor'].puts "completer, no possible completions found"
99
+ @completion_not_found_proc.call
100
+
101
+ Treefell['editor'].puts "completer, done"
102
+ @done_proc.call
103
+ end
104
+
105
+ def possible_completions
106
+ # completion matches is a history implementation and its in reverse order from what
107
+ # a user would expect
108
+ @completion_matches.reverse
109
+ end
110
+
111
+ def resize(matches)
112
+ if matches.any?
113
+ @completion_matches.resize(matches.length)
114
+ matches.each { |w| @completion_matches << w }
115
+ end
116
+ end
117
+
118
+ def select_next
119
+ @completion_matches.back
120
+ match = @completion_matches.get
121
+
122
+ Treefell['editor'].puts "completer, selecting next match=#{match.inspect} possible_completions=#{possible_completions.inspect}"
123
+ @completion_found_proc.call(completion: match, possible_completions: possible_completions)
124
+ end
125
+
126
+ def select_previous
127
+ @completion_matches.forward
128
+ match = @completion_matches.get
129
+
130
+ Treefell['editor'].puts "completer, selecting previous match=#{match.inspect} possible_completions=#{possible_completions.inspect}"
131
+ @completion_found_proc.call(completion: match, possible_completions: possible_completions)
132
+ end
133
+ end
91
134
  end
@@ -684,13 +684,13 @@ module RawLine
684
684
  end
685
685
 
686
686
  def completion_selected(completion)
687
- Treefell['editor'].puts "word-completion-selected #{completion}"
687
+ Treefell['editor'].puts "word-completion-selected #{completion.inspect}"
688
688
  move_to_position @line.word[:end]
689
689
  delete_n_characters(@line.word[:end] - @line.word[:start], true)
690
690
  write completion.to_s
691
691
 
692
692
  if @on_word_completion_selected
693
- Treefell['editor'].puts "word-completion-selected callback called with #{completion}"
693
+ Treefell['editor'].puts "word-completion-selected callback called with #{completioni}"
694
694
  @on_word_completion_selected.call(name: "word-completion-selected", payload: { completion: completion })
695
695
  end
696
696
  end
@@ -871,10 +871,12 @@ module RawLine
871
871
  @event_loop = Rawline::EventLoop.new(registry: @event_registry)
872
872
 
873
873
  @dom.on(:child_changed) do |*args|
874
+ Treefell['editor'].puts 'DOM child changed, re-rendering'
874
875
  @event_loop.add_event name: "render", source: @dom#, target: event[:target]
875
876
  end
876
877
 
877
878
  @dom.on :position_changed do |*args|
879
+ Treefell['editor'].puts 'DOM position changed, rendering cursor'
878
880
  @renderer.render_cursor(@dom.input_box)
879
881
  end
880
882
 
@@ -1,3 +1,3 @@
1
1
  module RawLine
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yap-rawline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabio Cevasco