Class: Textbringer::DeleteAction

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, insert_location, string) ⇒ DeleteAction

Returns a new instance of DeleteAction.



1832
1833
1834
1835
1836
# File 'lib/textbringer/buffer.rb', line 1832

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

Instance Attribute Details

#stringObject (readonly)

Returns the value of attribute string.



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

def string
  @string
end

Instance Method Details

#redoObject



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

def redo
  @buffer.goto_char(@insert_location)
  @buffer.delete_region(@insert_location,
                        @insert_location + @string.bytesize)
end

#undoObject



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

def undo
  @buffer.goto_char(@insert_location)
  @buffer.insert(@string)
  @buffer.goto_char(@location)
end