Class: Yatte::Selection

Inherits:
Object
  • Object
show all
Defined in:
lib/yatte/selection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSelection

Returns a new instance of Selection.



7
8
9
10
11
# File 'lib/yatte/selection.rb', line 7

def initialize
  @anchor_row = nil
  @anchor_col = nil
  @active = false
end

Instance Attribute Details

#anchor_colObject (readonly)

Returns the value of attribute anchor_col.



5
6
7
# File 'lib/yatte/selection.rb', line 5

def anchor_col
  @anchor_col
end

#anchor_rowObject (readonly)

Returns the value of attribute anchor_row.



5
6
7
# File 'lib/yatte/selection.rb', line 5

def anchor_row
  @anchor_row
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/yatte/selection.rb', line 19

def active?
  @active
end

#clearObject



23
24
25
26
27
# File 'lib/yatte/selection.rb', line 23

def clear
  @anchor_row = nil
  @anchor_col = nil
  @active = false
end

#contains?(row, col, cursor_row, cursor_col) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/yatte/selection.rb', line 40

def contains?(row, col, cursor_row, cursor_col)
  r = range(cursor_row, cursor_col)
  return false unless r

  start_row, start_col, end_row, end_col = r

  return false if row < start_row || row > end_row

  if start_row == end_row
    col >= start_col && col < end_col
  elsif row == start_row
    col >= start_col
  elsif row == end_row
    col < end_col
  else
    true
  end
end

#range(cursor_row, cursor_col) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/yatte/selection.rb', line 29

def range(cursor_row, cursor_col)
  return nil unless @active

  if @anchor_row < cursor_row ||
      (@anchor_row == cursor_row && @anchor_col <= cursor_col)
    [@anchor_row, @anchor_col, cursor_row, cursor_col]
  else
    [cursor_row, cursor_col, @anchor_row, @anchor_col]
  end
end

#start(row, col) ⇒ Object



13
14
15
16
17
# File 'lib/yatte/selection.rb', line 13

def start(row, col)
  @anchor_row = row
  @anchor_col = col
  @active = true
end