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.



1967
1968
1969
1970
1971
# File 'lib/textbringer/buffer.rb', line 1967

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

Instance Attribute Details

#stringObject (readonly)

Returns the value of attribute string.



1965
1966
1967
# File 'lib/textbringer/buffer.rb', line 1965

def string
  @string
end

Instance Method Details

#merge(s) ⇒ Object



1983
1984
1985
1986
1987
1988
1989
# File 'lib/textbringer/buffer.rb', line 1983

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

#redoObject



1978
1979
1980
1981
# File 'lib/textbringer/buffer.rb', line 1978

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

#undoObject



1973
1974
1975
1976
# File 'lib/textbringer/buffer.rb', line 1973

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