diff options
| author | Kevin Fischer <[email protected]> | 2020-04-06 06:58:42 +0900 |
|---|---|---|
| committer | Amir Rajan <[email protected]> | 2020-04-15 16:50:58 -0500 |
| commit | da0fdcfbd2bd9739fe056eb646920df79a32954c (patch) | |
| tree | 117e0ce5642e3bca4f7bcc375efbbf2c8a94c94a | |
| parent | 99305ca79118fa0704c8681f4019738b8c7a500d (diff) | |
| download | dragonruby-game-toolkit-contrib-da0fdcfbd2bd9739fe056eb646920df79a32954c.tar.gz dragonruby-game-toolkit-contrib-da0fdcfbd2bd9739fe056eb646920df79a32954c.zip | |
Make autocomplete work for global methods (methods of Kernel)
| -rw-r--r-- | dragon/console.rb | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/dragon/console.rb b/dragon/console.rb index 7f7e335..9a8b55f 100644 --- a/dragon/console.rb +++ b/dragon/console.rb @@ -84,10 +84,8 @@ module GTK end def autocomplete - return unless last_period_index - if !@last_autocomplete_prefix - @last_autocomplete_prefix = current_input_str[(last_period_index + 1)..-1] + @last_autocomplete_prefix = calc_autocomplete_prefix puts method_candidates(@last_autocomplete_prefix) else @@ -98,7 +96,7 @@ module GTK candidate = candidate[0..-2] + " = " if candidate.end_with? '=' @next_candidate_index += 1 @next_candidate_index = 0 if @next_candidate_index >= candidates.length - @current_input_str = @current_input_str[0..last_period_index] + candidate.to_s + self.current_input_str = display_autocomplete_candidate(candidate) end end @@ -113,8 +111,16 @@ module GTK current_input_str.rindex('.') end + def calc_autocomplete_prefix + if last_period_index + current_input_str[(last_period_index + 1)..-1] + else + current_input_str + end + end + def current_object - return nil unless last_period_index + return Kernel unless last_period_index Kernel.eval(current_input_str[0...last_period_index]) rescue NameError @@ -125,6 +131,14 @@ module GTK current_object.methods.map(&:to_s).select { |m| m.start_with? prefix } end + def display_autocomplete_candidate(candidate) + if last_period_index + @current_input_str[0..last_period_index] + candidate.to_s + else + candidate.to_s + end + end + def reset_autocomplete @last_autocomplete_prefix = nil @next_candidate_index = 0 |
