[Gutter] Augment Decoration to discern the line-number gutter from custom gutters

This commit is contained in:
Jess Lin
2015-02-03 18:34:51 -08:00
parent eb321a64c1
commit 58d6712b0e
4 changed files with 62 additions and 6 deletions

View File

@@ -5,6 +5,13 @@ Grim = require 'grim'
idCounter = 0
nextId = -> idCounter++
# Applies changes to a decorationsParam {Object} to make it possible to
# differentiate decorations on custom gutters versus the line-number gutter.
translateDecorationParamsOldToNew = (decorationParams) ->
if decorationParams.type is 'line-number'
decorationParams.gutterName = 'line-number'
decorationParams
# Essential: Represents a decoration that follows a {Marker}. A decoration is
# basically a visual representation of a marker. It allows you to add CSS
# classes to line numbers in the gutter, lines, and add selection-line regions
@@ -38,19 +45,29 @@ class Decoration
# type matches any in the array.
#
# Returns {Boolean}
# Note: 'line-number' is a special subtype of the 'gutter' type. I.e., a
# 'line-number' is a 'gutter', but a 'gutter' is not a 'line-number'.
@isType: (decorationProperties, type) ->
# 'line-number' is a special case of 'gutter'.
if _.isArray(decorationProperties.type)
type in decorationProperties.type
return true if type in decorationProperties.type
if type is 'gutter'
return true if 'line-number' in decorationProperties.type
return false
else
type is decorationProperties.type
if type is 'gutter'
return true if decorationProperties.type in ['gutter', 'line-number']
else
type is decorationProperties.type
###
Section: Construction and Destruction
###
constructor: (@marker, @displayBuffer, @properties) ->
constructor: (@marker, @displayBuffer, properties) ->
@emitter = new Emitter
@id = nextId()
@setProperties properties
@properties.id = @id
@flashQueue = null
@destroyed = false
@@ -134,7 +151,7 @@ class Decoration
setProperties: (newProperties) ->
return if @destroyed
oldProperties = @properties
@properties = newProperties
@properties = translateDecorationParamsOldToNew(newProperties)
@properties.id = @id
@emit 'updated', {oldParams: oldProperties, newParams: newProperties} if Grim.includeDeprecatedAPIs
@emitter.emit 'did-change-properties', {oldProperties, newProperties}

View File

@@ -1275,10 +1275,12 @@ class TextEditor extends Model
# * `position` (optional) Only applicable to decorations of type `overlay`,
# controls where the overlay view is positioned relative to the marker.
# Values can be `'head'` (the default), or `'tail'`.
# * `gutterName` (optional) Only applicable to the `gutter` type. If provided,
# the decoration will be applied to the gutter with the specified name.
#
# Returns a {Decoration} object
decorateMarker: (marker, decorationParams) ->
if includeDeprecatedAPIs and decorationParams.type is 'gutter'
if decorationParams.type is 'gutter' && !decorationParams.gutterName
deprecate("Decorations of `type: 'gutter'` have been renamed to `type: 'line-number'`.")
decorationParams.type = 'line-number'
@displayBuffer.decorateMarker(marker, decorationParams)