Class: VER::Text::Selection::Line

Inherits:
VER::Text::Selection show all
Defined in:
lib/ver/text/selection/line.rb

Instance Method Summary collapse

Instance Method Details

#copyObject



21
22
23
24
25
26
27
28
29
# File 'lib/ver/text/selection/line.rb', line 21

def copy
  buffer.with_register do |register|
    register.value = buffer.get("#{self}.first", "#{self}.last + 1 chars")
  end

  buffer.insert = "#{self}.first"
  clear
  finish
end

#eachObject



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ver/text/selection/line.rb', line 31

def each
  return Enumerator.new(self, :each) unless block_given?

  each_range do |range|
    fy, fx, ty, tx = *range.first, *range.last

    fy.upto(ty) do |y|
      sy, sx = *buffer.index("#{y}.0 linestart")
      ey, ex = *buffer.index("#{y}.0 lineend")
      yield sy, sx, ey, ex
    end
  end
end

#killObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ver/text/selection/line.rb', line 5

def kill
  indices = []
  chunks = each_range.map do |range|
    indices << range.first << (range.last + '1 chars')
    buffer.get(*indices.last(2))
  end

  buffer.with_register do |register|
    register.value = chunks.at(1) ? chunks : chunks.first
  end

  buffer.delete(*indices)
  clear
  finish
end

#mode_nameObject



45
46
47
# File 'lib/ver/text/selection/line.rb', line 45

def mode_name
  :select_line
end

#refreshObject



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ver/text/selection/line.rb', line 49

def refresh
  return unless @refresh
  start = anchor.index
  insert = buffer.at_insert
  clear

  if insert > start
    add(start.linestart, insert.lineend)
  else
    add(insert.linestart, start.lineend)
  end
end