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.



1681
1682
1683
1684
1685
# File 'lib/textbringer/buffer.rb', line 1681

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

Instance Method Details

#merge(s) ⇒ Object



1697
1698
1699
1700
1701
1702
1703
# File 'lib/textbringer/buffer.rb', line 1697

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

#redoObject



1692
1693
1694
1695
# File 'lib/textbringer/buffer.rb', line 1692

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

#undoObject



1687
1688
1689
1690
# File 'lib/textbringer/buffer.rb', line 1687

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