Class: Rvim::CompletionPopup

Inherits:
Object
  • Object
show all
Defined in:
lib/rvim/completion_popup.rb

Constant Summary collapse

DEFAULT_MAX_HEIGHT =
8
DEFAULT_MAX_WIDTH =
30

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contents:, pointer: 0, max_height: DEFAULT_MAX_HEIGHT, max_width: DEFAULT_MAX_WIDTH) ⇒ CompletionPopup

Returns a new instance of CompletionPopup.



11
12
13
14
15
16
17
# File 'lib/rvim/completion_popup.rb', line 11

def initialize(contents:, pointer: 0, max_height: DEFAULT_MAX_HEIGHT, max_width: DEFAULT_MAX_WIDTH)
  @contents = contents
  @max_height = max_height
  @max_width = max_width
  @scroll_top = 0
  self.pointer = pointer
end

Instance Attribute Details

#contentsObject

Returns the value of attribute contents.



8
9
10
# File 'lib/rvim/completion_popup.rb', line 8

def contents
  @contents
end

#max_heightObject

Returns the value of attribute max_height.



8
9
10
# File 'lib/rvim/completion_popup.rb', line 8

def max_height
  @max_height
end

#max_widthObject

Returns the value of attribute max_width.



8
9
10
# File 'lib/rvim/completion_popup.rb', line 8

def max_width
  @max_width
end

#pointerObject

Returns the value of attribute pointer.



9
10
11
# File 'lib/rvim/completion_popup.rb', line 9

def pointer
  @pointer
end

#scroll_topObject (readonly)

Returns the value of attribute scroll_top.



9
10
11
# File 'lib/rvim/completion_popup.rb', line 9

def scroll_top
  @scroll_top
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/rvim/completion_popup.rb', line 41

def empty?
  @contents.empty?
end

#needs_scrollbar?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/rvim/completion_popup.rb', line 49

def needs_scrollbar?
  @contents.size > visible_height
end

#sizeObject



45
46
47
# File 'lib/rvim/completion_popup.rb', line 45

def size
  @contents.size
end

#visible_heightObject



24
25
26
# File 'lib/rvim/completion_popup.rb', line 24

def visible_height
  [@contents.size, @max_height].min
end

#visible_rangeObject



28
29
30
31
32
33
# File 'lib/rvim/completion_popup.rb', line 28

def visible_range
  return (0...0) if @contents.empty?

  bottom = [@scroll_top + visible_height, @contents.size].min
  @scroll_top...bottom
end

#widthObject



35
36
37
38
39
# File 'lib/rvim/completion_popup.rb', line 35

def width
  return 0 if @contents.empty?

  [@contents.map(&:length).max, @max_width].min
end