Class: Textbringer::CompletionPopup
- Inherits:
-
Object
- Object
- Textbringer::CompletionPopup
- Defined in:
- lib/textbringer/completion_popup.rb
Constant Summary collapse
- MAX_VISIBLE_ITEMS =
10- MIN_WIDTH =
20- MAX_WIDTH =
60
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#selected_index ⇒ Object
readonly
Returns the value of attribute selected_index.
-
#start_point ⇒ Object
readonly
Returns the value of attribute start_point.
Class Method Summary collapse
Instance Method Summary collapse
- #accept ⇒ Object
- #cancel ⇒ Object
- #close ⇒ Object
- #current_item ⇒ Object
- #hide ⇒ Object
-
#initialize ⇒ CompletionPopup
constructor
A new instance of CompletionPopup.
- #select_next ⇒ Object
- #select_previous ⇒ Object
- #show(items:, start_point:, prefix: "") ⇒ Object
- #visible? ⇒ Boolean
Constructor Details
#initialize ⇒ CompletionPopup
Returns a new instance of CompletionPopup.
13 14 15 16 17 18 19 |
# File 'lib/textbringer/completion_popup.rb', line 13 def initialize @floating_window = nil @items = [] @selected_index = 0 @start_point = nil @prefix = "" end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
7 8 9 |
# File 'lib/textbringer/completion_popup.rb', line 7 def items @items end |
#selected_index ⇒ Object (readonly)
Returns the value of attribute selected_index.
7 8 9 |
# File 'lib/textbringer/completion_popup.rb', line 7 def selected_index @selected_index end |
#start_point ⇒ Object (readonly)
Returns the value of attribute start_point.
7 8 9 |
# File 'lib/textbringer/completion_popup.rb', line 7 def start_point @start_point end |
Class Method Details
.instance ⇒ Object
9 10 11 |
# File 'lib/textbringer/completion_popup.rb', line 9 def self.instance @instance ||= new end |
Instance Method Details
#accept ⇒ Object
67 68 69 70 71 72 |
# File 'lib/textbringer/completion_popup.rb', line 67 def accept return nil unless visible? && !@items.empty? item = current_item close item end |
#cancel ⇒ Object
74 75 76 77 |
# File 'lib/textbringer/completion_popup.rb', line 74 def cancel close nil end |
#close ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/textbringer/completion_popup.rb', line 38 def close if @floating_window @floating_window.close @floating_window = nil end @items = [] @selected_index = 0 @start_point = nil @prefix = "" end |
#current_item ⇒ Object
79 80 81 82 |
# File 'lib/textbringer/completion_popup.rb', line 79 def current_item return nil if @items.empty? @items[@selected_index] end |
#hide ⇒ Object
34 35 36 |
# File 'lib/textbringer/completion_popup.rb', line 34 def hide @floating_window&.hide end |
#select_next ⇒ Object
53 54 55 56 57 58 |
# File 'lib/textbringer/completion_popup.rb', line 53 def select_next return unless visible? && !@items.empty? @selected_index = (@selected_index + 1) % @items.size render @floating_window.redisplay end |
#select_previous ⇒ Object
60 61 62 63 64 65 |
# File 'lib/textbringer/completion_popup.rb', line 60 def select_previous return unless visible? && !@items.empty? @selected_index = (@selected_index - 1) % @items.size render @floating_window.redisplay end |
#show(items:, start_point:, prefix: "") ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/textbringer/completion_popup.rb', line 21 def show(items:, start_point:, prefix: "") @items = items @start_point = start_point @prefix = prefix @selected_index = 0 return if @items.empty? create_or_update_window render @floating_window.show end |
#visible? ⇒ Boolean
49 50 51 |
# File 'lib/textbringer/completion_popup.rb', line 49 def visible? @floating_window&.visible? || false end |