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.



1804
1805
1806
1807
1808
# File 'lib/textbringer/buffer.rb', line 1804

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

Instance Attribute Details

#stringObject (readonly)

Returns the value of attribute string.



1802
1803
1804
# File 'lib/textbringer/buffer.rb', line 1802

def string
  @string
end

Instance Method Details

#merge(s) ⇒ Object



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

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

#redoObject



1815
1816
1817
1818
# File 'lib/textbringer/buffer.rb', line 1815

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

#undoObject



1810
1811
1812
1813
# File 'lib/textbringer/buffer.rb', line 1810

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