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.



1948
1949
1950
1951
1952
# File 'lib/textbringer/buffer.rb', line 1948

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

Instance Attribute Details

#stringObject (readonly)

Returns the value of attribute string.



1946
1947
1948
# File 'lib/textbringer/buffer.rb', line 1946

def string
  @string
end

Instance Method Details

#merge(s) ⇒ Object



1964
1965
1966
1967
1968
1969
1970
# File 'lib/textbringer/buffer.rb', line 1964

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

#redoObject



1959
1960
1961
1962
# File 'lib/textbringer/buffer.rb', line 1959

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

#undoObject



1954
1955
1956
1957
# File 'lib/textbringer/buffer.rb', line 1954

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