mirror of
https://github.com/atom/atom.git
synced 2026-02-19 02:44:29 -05:00
Add DisplayBuffer.copy
This commit is contained in:
@@ -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: ->
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user