From 785ade897ecda6a73d87b9a95b6e3f83aaf97eb7 Mon Sep 17 00:00:00 2001 From: Jason Rudolph Date: Thu, 5 Oct 2017 09:55:33 -0400 Subject: [PATCH] =?UTF-8?q?=E2=98=A0=E2=98=95=20Decaffeinate=20src/gutter.?= =?UTF-8?q?coffee?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gutter.coffee | 95 ---------------------------------------- src/gutter.js | 107 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+), 95 deletions(-) delete mode 100644 src/gutter.coffee create mode 100644 src/gutter.js diff --git a/src/gutter.coffee b/src/gutter.coffee deleted file mode 100644 index 4521eeeb2..000000000 --- a/src/gutter.coffee +++ /dev/null @@ -1,95 +0,0 @@ -{Emitter} = require 'event-kit' -CustomGutterComponent = null - -DefaultPriority = -100 - -# Extended: Represents a gutter within a {TextEditor}. -# -# See {TextEditor::addGutter} for information on creating a gutter. -module.exports = -class Gutter - constructor: (gutterContainer, options) -> - @gutterContainer = gutterContainer - @name = options?.name - @priority = options?.priority ? DefaultPriority - @visible = options?.visible ? true - - @emitter = new Emitter - - ### - Section: Gutter Destruction - ### - - # Essential: Destroys the gutter. - destroy: -> - if @name is 'line-number' - throw new Error('The line-number gutter cannot be destroyed.') - else - @gutterContainer.removeGutter(this) - @emitter.emit 'did-destroy' - @emitter.dispose() - - ### - Section: Event Subscription - ### - - # Essential: Calls your `callback` when the gutter's visibility changes. - # - # * `callback` {Function} - # * `gutter` The gutter whose visibility changed. - # - # Returns a {Disposable} on which `.dispose()` can be called to unsubscribe. - onDidChangeVisible: (callback) -> - @emitter.on 'did-change-visible', callback - - # Essential: Calls your `callback` when the gutter is destroyed. - # - # * `callback` {Function} - # - # Returns a {Disposable} on which `.dispose()` can be called to unsubscribe. - onDidDestroy: (callback) -> - @emitter.once 'did-destroy', callback - - ### - Section: Visibility - ### - - # Essential: Hide the gutter. - hide: -> - if @visible - @visible = false - @gutterContainer.scheduleComponentUpdate() - @emitter.emit 'did-change-visible', this - - # Essential: Show the gutter. - show: -> - if not @visible - @visible = true - @gutterContainer.scheduleComponentUpdate() - @emitter.emit 'did-change-visible', this - - # Essential: Determine whether the gutter is visible. - # - # Returns a {Boolean}. - isVisible: -> - @visible - - # 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. - # - # ## Arguments - # - # * `marker` A {DisplayMarker} you want this decoration to follow. - # * `decorationParams` An {Object} representing the decoration. It is passed - # to {TextEditor::decorateMarker} as its `decorationParams` and so supports - # all options documented there. - # * `type` __Caveat__: set to `'line-number'` if this is the line-number - # gutter, `'gutter'` otherwise. This cannot be overridden. - # - # Returns a {Decoration} object - decorateMarker: (marker, options) -> - @gutterContainer.addGutterDecoration(this, marker, options) - - getElement: -> - @element ?= document.createElement('div') diff --git a/src/gutter.js b/src/gutter.js new file mode 100644 index 000000000..3bf7a72ea --- /dev/null +++ b/src/gutter.js @@ -0,0 +1,107 @@ +const {Emitter} = require('event-kit') + +const DefaultPriority = -100 + +// Extended: Represents a gutter within a {TextEditor}. +// +// See {TextEditor::addGutter} for information on creating a gutter. +module.exports = class Gutter { + constructor (gutterContainer, options) { + this.gutterContainer = gutterContainer + this.name = options && options.name + this.priority = (options && options.priority != null) ? options.priority : DefaultPriority + this.visible = (options && options.visible != null) ? options.visible : true + + this.emitter = new Emitter() + } + + /* + Section: Gutter Destruction + */ + + // Essential: Destroys the gutter. + destroy () { + if (this.name === 'line-number') { + throw new Error('The line-number gutter cannot be destroyed.') + } else { + this.gutterContainer.removeGutter(this) + this.emitter.emit('did-destroy') + this.emitter.dispose() + } + } + + /* + Section: Event Subscription + */ + + // Essential: Calls your `callback` when the gutter's visibility changes. + // + // * `callback` {Function} + // * `gutter` The gutter whose visibility changed. + // + // Returns a {Disposable} on which `.dispose()` can be called to unsubscribe. + onDidChangeVisible (callback) { + return this.emitter.on('did-change-visible', callback) + } + + // Essential: Calls your `callback` when the gutter is destroyed. + // + // * `callback` {Function} + // + // Returns a {Disposable} on which `.dispose()` can be called to unsubscribe. + onDidDestroy (callback) { + return this.emitter.once('did-destroy', callback) + } + + /* + Section: Visibility + */ + + // Essential: Hide the gutter. + hide () { + if (this.visible) { + this.visible = false + this.gutterContainer.scheduleComponentUpdate() + this.emitter.emit('did-change-visible', this) + } + } + + // Essential: Show the gutter. + show () { + if (!this.visible) { + this.visible = true + this.gutterContainer.scheduleComponentUpdate() + this.emitter.emit('did-change-visible', this) + } + } + + // Essential: Determine whether the gutter is visible. + // + // Returns a {Boolean}. + isVisible () { + return this.visible + } + + // 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. + // + // ## Arguments + // + // * `marker` A {DisplayMarker} you want this decoration to follow. + // * `decorationParams` An {Object} representing the decoration. It is passed + // to {TextEditor::decorateMarker} as its `decorationParams` and so supports + // all options documented there. + // * `type` __Caveat__: set to `'line-number'` if this is the line-number + // gutter, `'gutter'` otherwise. This cannot be overridden. + // + // Returns a {Decoration} object + decorateMarker (marker, options) { + return this.gutterContainer.addGutterDecoration(this, marker, options) + } + + getElement () { + if (this.element == null) this.element = document.createElement('div') + return this.element + } +}