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.



1838
1839
1840
1841
1842
# File 'lib/textbringer/buffer.rb', line 1838

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

Instance Attribute Details

#stringObject (readonly)

Returns the value of attribute string.



1836
1837
1838
# File 'lib/textbringer/buffer.rb', line 1836

def string
  @string
end

Instance Method Details

#merge(s) ⇒ Object



1854
1855
1856
1857
1858
1859
1860
# File 'lib/textbringer/buffer.rb', line 1854

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

#redoObject



1849
1850
1851
1852
# File 'lib/textbringer/buffer.rb', line 1849

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

#undoObject



1844
1845
1846
1847
# File 'lib/textbringer/buffer.rb', line 1844

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