Add DisplayBuffer.copy

This commit is contained in:
Nathan Sobo
2013-07-18 11:34:39 -07:00
parent 8b53b4d749
commit de1b69dbc9
4 changed files with 41 additions and 7 deletions

View File

@@ -154,10 +154,7 @@ class DisplayBufferMarker
isEqual: (other) ->
return false unless other instanceof @constructor
@getBufferRange().isEqual(other.getBufferRange()) and
@isReversed() is other.isReversed() and
@hasTail() is other.hasTail() and
_.isEqual(@getAttributes(), other.getAttributes())
@bufferMarker.isEqual(other.bufferMarker)
# Returns a {String} representation of the marker
inspect: ->

View File

@@ -1,8 +1,9 @@
_ = require 'underscore'
guid = require 'guid'
{Point, Range} = require 'telepath'
TokenizedBuffer = require 'tokenized-buffer'
RowMap = require 'row-map'
EventEmitter = require 'event-emitter'
{Point, Range} = require 'telepath'
Fold = require 'fold'
Token = require 'token'
DisplayBufferMarker = require 'display-buffer-marker'
@@ -20,7 +21,7 @@ class DisplayBuffer
### Internal ###
constructor: (@buffer, options={}) ->
@id = @constructor.idCounter++
@id = guid.create().toString()
@tokenizedBuffer = new TokenizedBuffer(@buffer, options)
@softWrapColumn = options.softWrapColumn ? Infinity
@markers = {}
@@ -32,6 +33,11 @@ class DisplayBuffer
@subscribe @buffer, 'markers-updated', @handleMarkersUpdated
@subscribe @buffer, 'marker-created', @handleMarkerCreated
copy: ->
newDisplayBuffer = new DisplayBuffer(@buffer, tabLength: @getTabLength())
@findMarkers(displayBufferId: @id).map (marker) -> marker.copy(displayBufferId: newDisplayBuffer.id)
newDisplayBuffer
updateAllScreenLines: ->
@maxLineLength = 0
@screenLines = []
@@ -109,6 +115,12 @@ class DisplayBuffer
@buffer.markRange([[startRow, 0], [endRow, Infinity]], @foldMarkerAttributes())
@foldForMarker(foldMarker)
isFoldedAtBufferRow: (bufferRow) ->
@largestFoldContainingBufferRow(bufferRow)?
isFoldedAtScreenRow: (screenRow) ->
@largestFoldContainingBufferRow(@bufferRowForScreenRow(screenRow))?
# Destroys the fold with the given id
destroyFoldWithId: (id) ->
@foldsByMarkerId[id]?.destroy()
@@ -405,6 +417,9 @@ class DisplayBuffer
getMarkers: ->
@buffer.getMarkers().map ({id}) => @getMarker(id)
getMarkerCount: ->
@buffer.getMarkerCount()
# Constructs a new marker at the given screen range.
#
# range - The marker {Range} (representing the distance between the head and tail)