Decoration Essential

Represents a decoration that follows a DisplayMarker. 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 around marked ranges of text.

Decoration objects are not meant to be created directly, but created with TextEditor::decorateMarker. eg.

range = editor.getSelectedBufferRange() # any range you like
marker = editor.markBufferRange(range)
decoration = editor.decorateMarker(marker, {type: 'line', class: 'my-line-class'})

Best practice for destroying the decoration is by destroying the DisplayMarker.

marker.destroy()

You should only use Decoration::destroy when you still need or do not own the marker.

Construction and Destruction

::destroy()

Destroy this marker decoration.

You can also destroy the marker if you own it, which will destroy this decoration.

Event Subscription

::onDidChangeProperties(callback)

When the Decoration is updated via Decoration::update.

Argument Description

callback

Function

event

Object

oldProperties

Object the old parameters the decoration used to have

newProperties

Object the new parameters the decoration now has

Return values

Returns a Disposable on which .dispose() can be called to unsubscribe.

::onDidDestroy(callback)

Invoke the given callback when the Decoration is destroyed

Argument Description

callback

Function

Return values

Returns a Disposable on which .dispose() can be called to unsubscribe.

Decoration Details

::getId()

An id unique across all Decoration objects

::getMarker()

Return values

Returns the marker associated with this Decoration

::isType(type)

Check if this decoration is of type type

Argument Description

type

String type like 'line-number', 'line', etc. type can also be an Array of Strings, where it will return true if the decoration’s type matches any in the array.

Return values

Returns Boolean

Properties

::getProperties()

Return values

Returns the Decoration’s properties.

::setProperties(newProperties)

Update the marker with new Properties. Allows you to change the decoration’s class.

Argument Description

newProperties

Object eg. {type: 'line-number', class: 'my-new-class'}