Class: Textbringer::InsertAction

Inherits:
UndoableAction show all
Defined in:
lib/textbringer/buffer.rb

Instance Attribute Summary collapse

Attributes inherited from UndoableAction

#location, #version

Instance Method Summary collapse

Constructor Details

#initialize(buffer, location, string) ⇒ InsertAction

Returns a new instance of InsertAction.



1764
1765
1766
1767
1768
# File 'lib/textbringer/buffer.rb', line 1764

def initialize(buffer, location, string)
  super(buffer, location)
  @string = string
  @copied = false
end

Instance Attribute Details

#stringObject (readonly)

Returns the value of attribute string.



1762
1763
1764
# File 'lib/textbringer/buffer.rb', line 1762

def string
  @string
end

Instance Method Details

#merge(s) ⇒ Object



1780
1781
1782
1783
1784
1785
1786
# File 'lib/textbringer/buffer.rb', line 1780

def merge(s)
  unless @copied
    @string = @string.dup
    @copied = true
  end
  @string.concat(s)
end

#redoObject



1775
1776
1777
1778
# File 'lib/textbringer/buffer.rb', line 1775

def redo
  @buffer.goto_char(@location)
  @buffer.insert(@string)
end

#undoObject



1770
1771
1772
1773
# File 'lib/textbringer/buffer.rb', line 1770

def undo
  @buffer.goto_char(@location)
  @buffer.delete_region(@location, @location + @string.bytesize)
end