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.



1819
1820
1821
1822
1823
# File 'lib/textbringer/buffer.rb', line 1819

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.



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

def string
  @string
end

Instance Method Details

#redoObject



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

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

#undoObject



1825
1826
1827
1828
1829
# File 'lib/textbringer/buffer.rb', line 1825

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