Class: Rvim::Selection
- Inherits:
-
Object
- Object
- Rvim::Selection
- Defined in:
- lib/rvim/selection.rb
Instance Attribute Summary collapse
-
#end_col ⇒ Object
readonly
Returns the value of attribute end_col.
-
#end_line ⇒ Object
readonly
Returns the value of attribute end_line.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#start_col ⇒ Object
readonly
Returns the value of attribute start_col.
-
#start_line ⇒ Object
readonly
Returns the value of attribute start_line.
Class Method Summary collapse
Instance Method Summary collapse
- #blockwise? ⇒ Boolean
- #charwise? ⇒ Boolean
- #each_segment(buffer_of_lines) ⇒ Object
- #includes?(line, col) ⇒ Boolean
- #linewise? ⇒ Boolean
Instance Attribute Details
#end_col ⇒ Object (readonly)
Returns the value of attribute end_col.
5 6 7 |
# File 'lib/rvim/selection.rb', line 5 def end_col @end_col end |
#end_line ⇒ Object (readonly)
Returns the value of attribute end_line.
5 6 7 |
# File 'lib/rvim/selection.rb', line 5 def end_line @end_line end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
5 6 7 |
# File 'lib/rvim/selection.rb', line 5 def mode @mode end |
#start_col ⇒ Object (readonly)
Returns the value of attribute start_col.
5 6 7 |
# File 'lib/rvim/selection.rb', line 5 def start_col @start_col end |
#start_line ⇒ Object (readonly)
Returns the value of attribute start_line.
5 6 7 |
# File 'lib/rvim/selection.rb', line 5 def start_line @start_line end |
Class Method Details
.from(mode, anchor, cursor, buffer_of_lines) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/rvim/selection.rb', line 7 def self.from(mode, anchor, cursor, buffer_of_lines) al, ac = anchor cl, cc = cursor sel = allocate sel.send(:initialize_from, mode, al, ac, cl, cc, buffer_of_lines) sel end |
Instance Method Details
#blockwise? ⇒ Boolean
23 24 25 |
# File 'lib/rvim/selection.rb', line 23 def blockwise? @mode == :block end |
#charwise? ⇒ Boolean
19 20 21 |
# File 'lib/rvim/selection.rb', line 19 def charwise? @mode == :char end |
#each_segment(buffer_of_lines) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rvim/selection.rb', line 48 def each_segment(buffer_of_lines) (@start_line..@end_line).each do |li| line = buffer_of_lines[li] || '' case @mode when :line yield li, 0, line.bytesize when :char first = li == @start_line ? @start_col : 0 last = li == @end_line ? @end_col + 1 : line.bytesize last = [last, line.bytesize].min first = [first, line.bytesize].min yield li, first, last when :block first = [@start_col, line.bytesize].min last = [@end_col + 1, line.bytesize].min yield li, first, last end end end |
#includes?(line, col) ⇒ Boolean
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rvim/selection.rb', line 27 def includes?(line, col) return false if line < @start_line || line > @end_line case @mode when :line true when :char if @start_line == @end_line col >= @start_col && col <= @end_col elsif line == @start_line col >= @start_col elsif line == @end_line col <= @end_col else true end when :block col >= @start_col && col <= @end_col end end |
#linewise? ⇒ Boolean
15 16 17 |
# File 'lib/rvim/selection.rb', line 15 def linewise? @mode == :line end |