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.



1817
1818
1819
1820
1821
# File 'lib/textbringer/buffer.rb', line 1817

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

Instance Method Details

#merge(s) ⇒ Object



1833
1834
1835
1836
1837
1838
1839
# File 'lib/textbringer/buffer.rb', line 1833

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

#redoObject



1828
1829
1830
1831
# File 'lib/textbringer/buffer.rb', line 1828

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

#undoObject



1823
1824
1825
1826
# File 'lib/textbringer/buffer.rb', line 1823

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