Class: Textbringer::InsertAction

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

Instance Attribute Summary

Attributes inherited from UndoableAction

#location, #version

Instance Method Summary collapse

Constructor Details

#initialize(buffer, location, string) ⇒ InsertAction

Returns a new instance of InsertAction.



1779
1780
1781
1782
1783
# File 'lib/textbringer/buffer.rb', line 1779

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

Instance Method Details

#merge(s) ⇒ Object



1795
1796
1797
1798
1799
1800
1801
# File 'lib/textbringer/buffer.rb', line 1795

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

#redoObject



1790
1791
1792
1793
# File 'lib/textbringer/buffer.rb', line 1790

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

#undoObject



1785
1786
1787
1788
# File 'lib/textbringer/buffer.rb', line 1785

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