Use DisplayMarkerLayers

I’m creating the DisplayLayer in the DisplayBuffer. In places where our
API deviates from DisplayBuffer, I’ll use the DisplayLayer directly from
as a property of TextEditor. Otherwise I’ll continue to delegate from
the DisplayLayer into the DisplayLayer to minimize impact until the
DisplayBuffer can be removed entirely.
This commit is contained in:
Nathan Sobo
2015-12-18 19:20:09 -07:00
parent 5292767084
commit caf6d7f473
8 changed files with 54 additions and 623 deletions

View File

@@ -116,8 +116,7 @@ class TextEditor extends Model
buffer, tabLength, softWrapped, ignoreInvisibles: @mini, largeFileMode,
@config, @assert, @grammarRegistry, @packageManager
})
@buffer = @displayBuffer.buffer
@displayLayer = buffer.addDisplayLayer({tabLength: @displayBuffer.getTabLength()})
{@buffer, @displayLayer} = @displayBuffer
@selectionsMarkerLayer ?= @addMarkerLayer(maintainHistory: true)
for marker in @selectionsMarkerLayer.getMarkers()
@@ -1427,7 +1426,7 @@ class TextEditor extends Model
Section: Decorations
###
# Essential: Add a decoration that tracks a {TextEditorMarker}. When the
# Essential: Add a decoration that tracks a {DisplayMarker}. When the
# marker moves, is invalidated, or is destroyed, the decoration will be
# updated to reflect the marker's state.
#
@@ -1448,28 +1447,28 @@ class TextEditor extends Model
# </div>
# ```
# * __overlay__: Positions the view associated with the given item at the head
# or tail of the given `TextEditorMarker`.
# * __gutter__: A decoration that tracks a {TextEditorMarker} in a {Gutter}. Gutter
# or tail of the given `DisplayMarker`.
# * __gutter__: A decoration that tracks a {DisplayMarker} in a {Gutter}. Gutter
# decorations are created by calling {Gutter::decorateMarker} on the
# desired `Gutter` instance.
#
# ## Arguments
#
# * `marker` A {TextEditorMarker} you want this decoration to follow.
# * `marker` A {DisplayMarker} you want this decoration to follow.
# * `decorationParams` An {Object} representing the decoration e.g.
# `{type: 'line-number', class: 'linter-error'}`
# * `type` There are several supported decoration types. The behavior of the
# types are as follows:
# * `line` Adds the given `class` to the lines overlapping the rows
# spanned by the `TextEditorMarker`.
# spanned by the `DisplayMarker`.
# * `line-number` Adds the given `class` to the line numbers overlapping
# the rows spanned by the `TextEditorMarker`.
# the rows spanned by the `DisplayMarker`.
# * `highlight` Creates a `.highlight` div with the nested class with up
# to 3 nested regions that fill the area spanned by the `TextEditorMarker`.
# to 3 nested regions that fill the area spanned by the `DisplayMarker`.
# * `overlay` Positions the view associated with the given item at the
# head or tail of the given `TextEditorMarker`, depending on the `position`
# head or tail of the given `DisplayMarker`, depending on the `position`
# property.
# * `gutter` Tracks a {TextEditorMarker} in a {Gutter}. Created by calling
# * `gutter` Tracks a {DisplayMarker} in a {Gutter}. Created by calling
# {Gutter::decorateMarker} on the desired `Gutter` instance.
# * `class` This CSS class will be applied to the decorated line number,
# line, highlight, or overlay.
@@ -1477,16 +1476,16 @@ class TextEditor extends Model
# corresponding view registered. Only applicable to the `gutter` and
# `overlay` types.
# * `onlyHead` (optional) If `true`, the decoration will only be applied to
# the head of the `TextEditorMarker`. Only applicable to the `line` and
# the head of the `DisplayMarker`. Only applicable to the `line` and
# `line-number` types.
# * `onlyEmpty` (optional) If `true`, the decoration will only be applied if
# the associated `TextEditorMarker` is empty. Only applicable to the `gutter`,
# the associated `DisplayMarker` is empty. Only applicable to the `gutter`,
# `line`, and `line-number` types.
# * `onlyNonEmpty` (optional) If `true`, the decoration will only be applied
# if the associated `TextEditorMarker` is non-empty. Only applicable to the
# if the associated `DisplayMarker` is non-empty. Only applicable to the
# `gutter`, `line`, and `line-number` types.
# * `position` (optional) Only applicable to decorations of type `overlay`,
# controls where the overlay view is positioned relative to the `TextEditorMarker`.
# controls where the overlay view is positioned relative to the `DisplayMarker`.
# Values can be `'head'` (the default), or `'tail'`.
#
# Returns a {Decoration} object
@@ -1497,7 +1496,7 @@ class TextEditor extends Model
# marker layer. Can be used to decorate a large number of markers without
# having to create and manage many individual decorations.
#
# * `markerLayer` A {TextEditorMarkerLayer} or {MarkerLayer} to decorate.
# * `markerLayer` A {DisplayMarkerLayer} or {MarkerLayer} to decorate.
# * `decorationParams` The same parameters that are passed to
# {decorateMarker}, except the `type` cannot be `overlay` or `gutter`.
#
@@ -1515,7 +1514,7 @@ class TextEditor extends Model
#
# Returns an {Object} of decorations in the form
# `{1: [{id: 10, type: 'line-number', class: 'someclass'}], 2: ...}`
# where the keys are {TextEditorMarker} IDs, and the values are an array of decoration
# where the keys are {DisplayMarker} IDs, and the values are an array of decoration
# params objects attached to the marker.
# Returns an empty object when no decorations are found
decorationsForScreenRowRange: (startScreenRow, endScreenRow) ->
@@ -1610,7 +1609,7 @@ class TextEditor extends Model
# region in any way, including changes that end at the marker's
# start or start at the marker's end. This is the most fragile strategy.
#
# Returns a {TextEditorMarker}.
# Returns a {DisplayMarker}.
markBufferRange: (args...) ->
@displayBuffer.markBufferRange(args...)
@@ -1645,7 +1644,7 @@ class TextEditor extends Model
# region in any way, including changes that end at the marker's
# start or start at the marker's end. This is the most fragile strategy.
#
# Returns a {TextEditorMarker}.
# Returns a {DisplayMarker}.
markScreenRange: (args...) ->
@displayBuffer.markScreenRange(args...)
@@ -1655,7 +1654,7 @@ class TextEditor extends Model
# * `position` A {Point} or {Array} of `[row, column]`.
# * `options` (optional) See {TextBuffer::markRange}.
#
# Returns a {TextEditorMarker}.
# Returns a {DisplayMarker}.
markBufferPosition: (args...) ->
@displayBuffer.markBufferPosition(args...)
@@ -1665,11 +1664,11 @@ class TextEditor extends Model
# * `position` A {Point} or {Array} of `[row, column]`.
# * `options` (optional) See {TextBuffer::markRange}.
#
# Returns a {TextEditorMarker}.
# Returns a {DisplayMarker}.
markScreenPosition: (args...) ->
@displayBuffer.markScreenPosition(args...)
# Essential: Find all {TextEditorMarker}s on the default marker layer that
# Essential: Find all {DisplayMarker}s on the default marker layer that
# match the given properties.
#
# This method finds markers based on the given properties. Markers can be
@@ -1692,14 +1691,14 @@ class TextEditor extends Model
findMarkers: (properties) ->
@displayBuffer.findMarkers(properties)
# Extended: Get the {TextEditorMarker} on the default layer for the given
# Extended: Get the {DisplayMarker} on the default layer for the given
# marker id.
#
# * `id` {Number} id of the marker
getMarker: (id) ->
@displayBuffer.getMarker(id)
# Extended: Get all {TextEditorMarker}s on the default marker layer. Consider
# Extended: Get all {DisplayMarker}s on the default marker layer. Consider
# using {::findMarkers}
getMarkers: ->
@displayBuffer.getMarkers()
@@ -1721,11 +1720,11 @@ class TextEditor extends Model
#
# This API is experimental and subject to change on any release.
#
# Returns a {TextEditorMarkerLayer}.
# Returns a {DisplayMarkerLayer}.
addMarkerLayer: (options) ->
@displayBuffer.addMarkerLayer(options)
# Public: *Experimental:* Get a {TextEditorMarkerLayer} by id.
# Public: *Experimental:* Get a {DisplayMarkerLayer} by id.
#
# * `id` The id of the marker layer to retrieve.
#
@@ -1736,14 +1735,14 @@ class TextEditor extends Model
getMarkerLayer: (id) ->
@displayBuffer.getMarkerLayer(id)
# Public: *Experimental:* Get the default {TextEditorMarkerLayer}.
# Public: *Experimental:* Get the default {DisplayMarkerLayer}.
#
# All marker APIs not tied to an explicit layer interact with this default
# layer.
#
# This API is experimental and subject to change on any release.
#
# Returns a {TextEditorMarkerLayer}.
# Returns a {DisplayMarkerLayer}.
getDefaultMarkerLayer: ->
@displayBuffer.getDefaultMarkerLayer()
@@ -1950,7 +1949,7 @@ class TextEditor extends Model
getCursorsOrderedByBufferPosition: ->
@getCursors().sort (a, b) -> a.compare(b)
# Add a cursor based on the given {TextEditorMarker}.
# Add a cursor based on the given {DisplayMarker}.
addCursor: (marker) ->
cursor = new Cursor(editor: this, marker: marker, config: @config)
@cursors.push(cursor)
@@ -2299,7 +2298,7 @@ class TextEditor extends Model
# Extended: Select the range of the given marker if it is valid.
#
# * `marker` A {TextEditorMarker}
# * `marker` A {DisplayMarker}
#
# Returns the selected {Range} or `undefined` if the marker is invalid.
selectMarker: (marker) ->
@@ -2425,9 +2424,9 @@ class TextEditor extends Model
_.reduce(tail, reducer, [head])
return result if fn?
# Add a {Selection} based on the given {TextEditorMarker}.
# Add a {Selection} based on the given {DisplayMarker}.
#
# * `marker` The {TextEditorMarker} to highlight
# * `marker` The {DisplayMarker} to highlight
# * `options` (optional) An {Object} that pertains to the {Selection} constructor.
#
# Returns the new {Selection}.