Files
atom/src/packages/command-panel/lib/operation.coffee
Kevin Sawicki 699212a13e Always pull line text from buffer
This accounts for positional changes that may occur if the marker
the operation is tracking moves.
2013-04-02 14:24:36 -07:00

37 lines
989 B
CoffeeScript

module.exports =
class Operation
constructor: ({@project, @path, @buffer, @bufferRange, @newText, @preserveSelection, @errorMessage}) ->
if @buffer?
@buffer.retain()
@getMarker()
getMarker: ->
@marker ?= @getBuffer().markRange(@bufferRange)
getBuffer: ->
@buffer ?= @project.bufferForPath(@path).retain()
getPath: ->
path = @path ? @getBuffer().getPath()
@project.relativize(path)
getBufferRange: ->
@getBuffer().getMarkerRange(@getMarker())
execute: (editSession) ->
@getBuffer().change(@getBufferRange(), @newText) if @newText
@getBufferRange() unless @preserveSelection
preview: ->
range = @getBufferRange()
line = @getBuffer().lineForRow(range.start.row)
prefix = line[0...range.start.column]
match = line[range.start.column...range.end.column]
suffix = line[range.end.column..]
{prefix, suffix, match, range}
destroy: ->
@buffer?.destroyMarker(@marker) if @marker?
@buffer?.release()