mirror of
https://github.com/atom/atom.git
synced 2026-02-16 17:45:24 -05:00
This accounts for positional changes that may occur if the marker the operation is tracking moves.
37 lines
989 B
CoffeeScript
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()
|